我努力理解我为什么要使用MultipartFormDataStreamProvider时,我可以得到所有使用该信息HttpContext.Current。
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"];
于此:
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 - 我想建立一个ApiController接受文件上传。我读过这篇文章www.asp/web-api/overview/working-with-http/sending-html-form-data,-part-2.
推荐答案这是我发现的 MSDN 。我想,这可能会帮助你。
This is what I found on MSDN. I think this might help you.
流提供商着眼于在内容处置的头字段并基于A 文件名参数presence的输出流。如果A 文件名的参数是present在内容处置的头字段然后身体部分被写入一个FileStream,否则将被写入一个MemoryStream。这使得它方便处理MIME多HTML表单数据是表单数据和文件内容的组合。
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.
更多推荐
MultipartFormDataStreamProvider VS HttpContext.Current
发布评论