WebAPI上传错误。 MIME多部分流的预期结束。 MIME多部分消息未完成
作为MVC4的WebAPI的一部分,我一直在关注本教程以支持文件上传: http : //blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web -api.aspx 。
当我的控制器收到请求时,它会抱怨“MIME多部分消息未完成”。 有没有人有关于如何调试这个的任何提示? 我已经尝试将流的位置重置为0,因为在它遇到处理程序之前还有其他东西在读取它之前。
我的HTML看起来像这样:
和我的控制器的Post方法如下:
public Task<IEnumerable> Post() { if (Request.Content.IsMimeMultipartContent()) { Stream reqStream = Request.Content.ReadAsStreamAsync().Result; if (reqStream.CanSeek) { reqStream.Position = 0; } string fullPath = HttpContext.Current.Server.MapPath("~/App_Data"); var streamProvider = new MultipartFormDataStreamProvider(fullPath); var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception); var fileInfo = streamProvider.FileData.Select(i => { var info = new FileInfo(i.LocalFileName); return "File uploaded as " + info.FullName + " (" + info.Length + ")"; }); return fileInfo; }); return task; } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Invalid Request!")); } }
我错过了什么明显的吗?>
您可以尝试在输入文件中添加“name”属性吗?
- 为什么Request.Form.ToString()的返回值与NameValueCollection.ToString()的结果不同
- 在ASP.NETunit testing中模拟HttpContext.server.MapPath
- 如何使用twitter api获取twitter用户的电子邮件地址
- 如何在ASP.NET中获得提示值?
- 使用Web窗体进行ASP.NET路由
- 使用javascript函数在特定条件下从代码后面调用
- System.Uri类截断尾随’。’ 人物
- 尝试使用.netstandard 2程序集时,Web Api 2运行时错误
- 如何获取使用短名称格式化的Server.MapPath()(8.3 MS-DOS格式)?