I am struggling to understand why would I want to use MultipartFormDataStreamProvider when I can get all the information using HttpContext.Current.
It is much easier to do this:
var mydata = HttpContext.Current.Request.Form["mydata"];
than this:
string root = HttpContext.Current.Server.MapPath("~/somedir"); var provider = new MultipartFormDataStreamProvider(root); this.Request.Content.ReadAsMultipartAsync(provider).ContinueWith(t => { var mydata = provider.Contents.First(c => c.Headers.ContentDisposition.Name == "\"mydata\"").ReadAsStringAsync().Result; });
PS - I am trying to build an ApiController to accept file uploads. I've read this article http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2.
This is what I found on MSDN. I think this might help you.
The stream provider looks at the Content-Disposition header field and determines an output Stream based on the presence of a filename parameter. If a filename parameter is present in the Content-Disposition header field then the body part is written to a FileStream, otherwise it is written to a MemoryStream. This makes it convenient to process MIME Multipart HTML Form data which is a combination of form data and file content.
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