Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultipartFormDataStreamProvider vs HttpContext.Current

Tags:

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.

like image 362
niaher Avatar asked Jul 31 '13 10:07

niaher


1 Answers

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.

like image 187
Guanxi Avatar answered Oct 14 '22 23:10

Guanxi