上传大文件时的Azure App Service问题:MIME多部分流的意外结束

时间:2016-01-08 03:38:47

标签: asp.net-mvc azure iis asp.net-web-api azure-web-sites

我有一个基于AngularJS的Web界面,将zip文件发送到ApiController。我收到了文件:

public async Task<UploadImportPackageResponse> Package()
{
    var provider = new MultipartMemoryStreamProvider();
    await this.Request.Content.ReadAsMultipartAsync(provider);
    var file = provider.Contents.FirstOrDefault(p => p.Headers.ContentDisposition.Name == "\"file\"");

这在我的开发机器上,在我们的本地测试服务器上完全正常,但不在我们的Azure应用服务暂存站点上。

在Azure上,它会抛出以下错误:

  

MIME多部分流的意外结束。 MIME多部分邮件未完成。

  System.IO.IOException:
  at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser+<ParseBuffer>d__0.MoveNext (System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Net.Http.HttpContentMultipartExtensions+<MultipartReadAsync>d__8.MoveNext (System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Net.Http.HttpContentMultipartExtensions+<ReadAsMultipartAsync>d__0`1.MoveNext (System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at Test.Web.Areas.Admin.Controllers.ImportController+<Package>d__2.MoveNext (Test.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Threading.Tasks.TaskHelpersExtensions+<CastToObject>d__3`1.MoveNext (System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Web.Http.Controllers.ApiControllerActionInvoker+<InvokeActionAsyncCore>d__0.MoveNext (System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Web.Http.Controllers.ActionFilterResult+<ExecuteAsync>d__2.MoveNext (System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
  at System.Web.Http.Controllers.ExceptionFilterResult+<ExecuteAsync>d__0.MoveNext (System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)

这是我到目前为止所知道的:

  1. 1.5 MB文件上传很好,但12 MB文件没有。 (使用maxRequestLength="256000"&amp; maxAllowedContentLength="262144000"
  2. 我使用Charles Proxy捕获导致Azure上的错误的请求,并针对我的本地计算机重新执行它,在那里它没有导致任何错误。所以我确信这是服务器方面的问题。不是客户端问题。
  3. 我最好的猜测是服务器将请求缩短。但我不知道为什么,或者要更改哪些配置来解决此问题。

1 个答案:

答案 0 :(得分:0)

在与Azure支持人员交谈后,他们提到他们已经在他们的生产代码中修复了这样的错误,因此我浏览了所有相关的Microsoft nuget软件包,并意识到MS已经发布了新版本的Microsoft.AspNet.WebApi (以及相关软件包Client,Core,HelpPage和WebHost)

所以Update-Package Microsoft.AspNet.WebApi为我做了诀窍。

所以简短的回答是:

确保您安装的5.2.3版本为Microsoft.AspNet.WebApi或更高版本。