文件上传 – 如何解决邮递员中的文件上传错误?
发布时间:2020-12-15 19:42:42 所属栏目:asp.Net 来源:网络整理
导读:我在我的项目中使用webapi上传文件.我正在和邮递员一起测试.但是,Request.Content.IsMimeMultipartContent()始终返回false. 邮差截图: FileUploadController代码: public async TaskHttpResponseMessage UserImageUpload() { try { if (!Request.Content.I
我在我的项目中使用webapi上传文件.我正在和邮递员一起测试.但是,Request.Content.IsMimeMultipartContent()始终返回false.
邮差截图: FileUploadController代码: public async Task<HttpResponseMessage> UserImageUpload() { try { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var userImageUploadPath = HttpContext.Current.Server.MapPath(CommonParameters.UserProfileImageServerPath); var streamProvider = new CustomMultipartFormDataStreamProvider(userImageUploadPath); await Request.Content.ReadAsMultipartAsync(streamProvider); var files = new List<string>(); foreach (MultipartFileData file in streamProvider.FileData) { files.Add(Path.GetFileName(file.LocalFileName)); } return Request.CreateResponse(HttpStatusCode.OK,files); } catch (Exception exception) { logger.ErrorFormat("An error occured in UserImageUpload() Method - Class:FileUploadController - Message:{0}",exception); return Request.CreateResponse(HttpStatusCode.BadRequest); } } 解决方法
这是邮差错误.尝试删除Content-Type标头.发送实际的帖子时,浏览器会自动添加正确的标题并创建边界.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- 在ASP.NET MVC中为复杂数据验证放置数据管理规则
- asp.net – Stack Overflow的Mini Profiler
- 字符串拆分ASP.NET / C#
- Asp.net URL重写
- entity-framework – ViewModels和MVC中Entity F
- 设计模式 – 如何在自己的应用程序域中分离webap
- asp.net-mvc-5 – 如何在Asp.Net Identity Frame
- System.Net.ServicePointManager.DefaultConnect
- .net – 部署预编译的Razor视图并删除Views文件夹
- 内存数据库之Apache Ingite
热点阅读