MultipartFormDataStreamProvider VS HttpContext.Current [英] MultipartFormDataStreamProvider vs HttpContext.Current

查看:178
本文介绍了MultipartFormDataStreamProvider VS HttpContext.Current的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我努力理解我为什么要使用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接受文件上传。我读过这篇文章<一个href="http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2">http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2.

推荐答案

这是我发现的<一个href="http://msdn.microsoft.com/en-us/library/system.net.http.multipartformdatastreamprovider%28v=vs.118%29.aspx"相对=nofollow> 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆