栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何接受文件POST

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何接受文件POST

看到http://www.asp.net/web-api/overview/formats-and-model-binding/html-forms-
and-multipart-
mime#multipartmime

,尽管我认为这篇文章使它看起来比确实是。

基本上,

public Task<HttpResponseMessage> PostFile() {     HttpRequestMessage request = this.Request;     if (!request.Content.IsMimeMultipartContent())     {         throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);     }    string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/uploads");     var provider = new MultipartFormDataStreamProvider(root);    var task = request.Content.ReadAsMultipartAsync(provider).         ContinueWith<HttpResponseMessage>(o =>     {        string file1 = provider.BodyPartFileNames.First().Value;        // this is the file name on the server where the file was saved        return new HttpResponseMessage()         {  Content = new StringContent("File uploaded.")         };     }     );     return task; }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433089.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号