简体   繁体   English

上传大文件 - Azure App Service 上的 502 bad gateway 错误

[英]Upload large file - 502 bad gateway error on Azure App Service

I have a problem when I upload the large file on Azure.我在 Azure 上上传大文件时遇到问题。 I am working on an ASP.NET Core 5.0 API project.我正在研究 ASP.NET Core 5.0 API 项目。 I have implemented functionality regarding Microsoft recommendation .我已经实现了有关Microsoft 推荐的功能。 Moreover, I added a pooling mechanism so the frontend application has another endpoint to check upload status.此外,我添加了一个池机制,因此前端应用程序有另一个端点来检查上传状态。 Everything works fine when I run locally but I have a problem with a large file on Azure.当我在本地运行时一切正常,但我在 Azure 上遇到大文件问题。 My API is using Azure App Service Premium P1v3.我的 API 正在使用 Azure 应用服务高级版 P1v3。 It returns a 502 bad gateway for large files (above 1GB).它为大文件(超过 1GB)返回 502 错误网关。

I made a tests and 98 % time consuming is reading stream.我做了一个测试,98% 的时间是读取 stream。 From Microsft docs it is:从 Microsft 文档中它是:

if (MultipartRequestHelper
                .HasFileContentDisposition(contentDisposition))
            {
                untrustedFileNameForStorage = contentDisposition.FileName.Value;
                // Don't trust the file name sent by the client. To display
                // the file name, HTML-encode the value.
                trustedFileNameForDisplay = WebUtility.HtmlEncode(
                        contentDisposition.FileName.Value);

                streamedFileContent = 
                    await FileHelpers.ProcessStreamedFile(section, contentDisposition, 
                        ModelState, _permittedExtensions, _fileSizeLimit);

                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }
            }

I know there is a load balancer timeout of 230 seconds on Azure App Service but when I test it using postman in most cases 502 is being returned after 30 seconds.我知道 Azure 应用服务上有 230 秒的负载均衡器超时,但是当我使用 postman 测试它时,在大多数情况下,30 秒后返回 502。

Maybe I need to set some configuration feature on Azure App Service?也许我需要在 Azure App Service 上设置一些配置功能? Always on is enabled.始终开启已启用。

I would like to stay with Azure App Service, but I was thinking about migrating to Azure App service or allow the Frontend application to upload files directly to Azure Blob Storage.我想继续使用 Azure 应用服务,但我正在考虑迁移到 Azure 应用服务或允许前端应用程序将文件直接上传到 Z3A580F142203677F13F0BC30898F63F 存储。

Do you have any idea how to solve it?你知道如何解决它吗?

Newset新闻组

Uploading and Downloading large files in ASP.NET Core 3.1? 在 ASP.NET Core 3.1 中上传和下载大文件?

The previous answers are based on only using app services, but it is not recommended to store large files in app services.前面的答案都是基于只使用应用服务,但不建议在应用服务中存储大文件。 The first is that future updates will become slower and slower, and the second is that the disk space will soon be used up.一是以后更新会越来越慢,二是磁盘空间很快就会用完。

So it is recommended to use azure storage.所以推荐使用azure存储。 If you use azure storage, suggestion 2 is recommended for larger files to upload large files in chunks.如果你使用azure存储,建议2对于大文件,分块上传大文件。

Preview预习

Please confirm whether the large file can be transferred successfully even if the error message returns a 500 error.即使报错信息返回500错误,请确认大文件是否可以传输成功。

I have studied this phenomenon before, and each browser is different, and the 500 error time is roughly between 230s-300s.之前研究过这个现象,每个浏览器都不一样,500错误时间大致在230s-300s之间。 But looking through the log, the program continues to run.但是查看日志,程序继续运行。

Related Post:相关帖子:

The request timed out. 请求超时。 The web server failed to respond within the specified time web服务器未能在指定时间内响应

So there are two suggestions I give, you can refer to:所以我给出两个建议,大家可以参考:

Suggestion 1:建议一:

It is recommended to create an http interface (assuming the name is getStatus) in your program to receive file upload progress, similar to processbar.建议在你的程序中创建一个http接口(假设名称为getStatus)来接收文件上传进度,类似于processbar。 When the file starts to transfer, monitor the upload progress, upload the file interface, return HttpCode 201 accept, then the status value is obtained through getStatus, when it reaches 100%, it returns success.当文件开始传输时,监听上传进度,上传文件界面,返回HttpCode 201 accept,然后通过getStatus获取状态值,达到100%时返回成功。

Suggestion 2:建议二:

Use MultipartRequestHelper to cut/slice large file.使用MultipartRequestHelper剪切/切片大文件。 Your usage maybe wrong.您的用法可能是错误的。 Please refer below post.请参考下面的帖子。

Dealing with large file uploads on ASP.NET Core 1.0 处理 ASP.NET Core 1.0 上的大文件上传

The version of .net core is inconsistent, but the idea is the same. .net内核版本不一致,但思路是一样的。

Facing similar issue on uploading document of larger size(up to 100MB) through as.net core api hosted as azure app gateway and have set timeout to 10min and applied these attributes on action通过 as.net core api 上传较大尺寸(最大 100MB)的文档时面临类似问题,托管为 azure 应用程序网关,并将超时设置为 10 分钟并将这些属性应用于操作
[RequestFormLimits(MultipartBodyLengthLimit = 209715200)] [RequestSizeLimit(209715200)] Even kestrel has configured to accept 200MB UseKestrel(options => [RequestFormLimits(MultipartBodyLengthLimit = 209715200)] [RequestSizeLimit(209715200)] 甚至红隼已配置为接受 200MB UseKestrel(options =>

               {
                    options.Limits.MaxRequestBodySize = 209715200;
                    options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10);
                });

The file content is in base64 format in request object.请求 object 中的文件内容为 base64 格式。 Appreciate if any help on this problem.感谢您对这个问题是否有任何帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 502 错误:使用 IronPDF 的 Azure 应用服务上的网关错误 - 502 Error: Bad Gateway on Azure App Service with IronPDF Azure /映像请求502(错误网关)错误 - 间歇性 - Azure / Image request 502 (Bad gateway) error - intermittent 如何解决 502 Bad Gateway 错误 - How to troubleshoot 502 Bad Gateway error 为什么会发生“(502) Bad Gateway”错误? - Why "(502) Bad Gateway" error happen? 上传大文件时 502 Bad Gateway nginx 和 ASP.NET Core 3.1 - 502 Bad Gateway nginx and ASP.NET Core 3.1 when upload big file 错误(502)错误的网关:当尝试使用WebChat通道访问Azure上部署的聊天机器人时 - Error (502) Bad Gateway: When trying to access chatbot deployed on Azure using WebChat channel 来自Azure AppService的GET请求返回自身将返回502 Bad Gateway错误 - GET Request from an Azure AppService back to itself returns a 502 Bad Gateway error 调用Web服务返回远程服务器返回错误:(502)错误的网关 - Calling web service returns The remote server returned an error: (502) Bad Gateway Azure CDN终结点通过502提供错误的网关 - Azure CDN endpoint giving 502 bad gateway with https 远程服务器返回了意外的响应:(502)Azure WCF中的错误网关 - The remote server returned an unexpected response: (502) Bad Gateway in Azure WCF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM