首页 > 解决方案 > 将大文件上传到 Azure 中的 dotnetcore 应用程序失败 (404)

问题描述

我无法上传大文件,我不确定它是否仍然是大小限制或超时。

在控制器端点上,我尝试了我找到的所有属性(一次)

        [HttpPost("[action]")]
        [DisableRequestSizeLimit]
        [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue, BufferBodyLengthLimit = long.MaxValue)]
        [RequestSizeLimit(int.MaxValue)]
        public async Task UploadForm()

在“ConfigureServices”期间,我还设置了这个:

      services.Configure<FormOptions>(options =>
        {
            options.MemoryBufferThreshold = int.MaxValue;
            options.ValueLengthLimit = int.MaxValue;
            options.ValueCountLimit = int.MaxValue;
            options.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
        });

但是上传文件的一部分后我仍然收到 404 错误(30 MB 已经太多了)。

然后我什至尝试使用以下代码设置红隼,但应用程序甚至无法启动(502)

.UseKestrel((KestrelServerOptions o) =>
            {
                o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(120);
                o.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(120);
                o.Limits.MaxRequestBodySize = null;
            })

标签: azure-web-app-serviceasp.net-core-3.0

解决方案


看看这个官方文档

解决方案:

更改 的值maxAllowedContentLength

在 Web.config 中添加这些代码(在 Kudu 上的 site/wwwroot 下):

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <requestLimits maxAllowedContentLength="<valueInBytes>"/>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

这应该无需重新启动即可工作。


推荐阅读