I'm using the MultipartFormDataContent to upload a file to a rest API. This is working well, but my questions focuses on the proper way to use the Add(...) method to include the file content. Currently I am doing such:
string fileName = "foobar.txt";
MultipartFormDataContent formContent = new MultipartFormDataContent();
ByteArrayContent byteArray = ...;
formContent.Add(byteArray, "file", fileName);
...
again, this works - I am trying to understand the parameters to the Add(...) method. In the MSDN documentation at: https://msdn.microsoft.com/en-us/library/system.net.http.multipartformdatacontent(v=vs.118).aspx
it has two add methods:
however neither has a description listed, and when drilling into the methods themselves, the parameters are only described (again without descriptions) as:
so, my specific questions in this context are:
It is written into the content disposition header. it looks like you can leave it off for a file upload. name looks like it corresponds to the input name.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
As per the method with three parameters, following's a brief description for each param.
public void Add(HttpContent content, string name, string fileName);
content - content that needs to be sent (Ex: array, file).
name - Name for that content. This is essential if the web API has to search for a specific name.
filename - The name which'll be added to the content-disposition header of the message. This will be used by the web API to save the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With