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看起来像这样:

Select file(s) to upload :

和我的控制器的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”属性吗?