gpt4 book ai didi

asp.net-mvc - Azure 应用服务上传大文件时出现问题 : Unexpected end of MIME multipart stream

转载 作者:行者123 更新时间:2023-12-03 03:13:00 26 4
gpt4 key购买 nike

我有一个基于 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 上,它会抛出以下错误:

Unexpected end of MIME multipart stream. MIME multipart message is not complete.

  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”maxAllowedContentLength =“262144000”)
  2. 我使用 Charles Proxy 捕获了在 Azure 上导致错误的请求,并在我的本地计算机上重新执行该请求,没有导致任何错误。所以我确信这是服务器端问题。不是客户端问题。

我最好的猜测是服务器缩短了请求。但我不知道为什么,也不知道需要更改哪些配置来解决此问题。

最佳答案

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

所以 Update-Package Microsoft.AspNet.WebApi 为我解决了这个问题。

所以简短的答案是:

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

关于asp.net-mvc - Azure 应用服务上传大文件时出现问题 : Unexpected end of MIME multipart stream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com