MultipartFormDataStreamProvider VS HttpContext.Current

编程入门 行业动态 更新时间:2024-10-16 22:24:11
本文介绍了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接受文件上传。我读过这篇文章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

本文发布于:2023-11-13 15:01:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MultipartFormDataStreamProvider   HttpContext   Current

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!