Home > Back-end >  error 502 bad gateway when download file angular 11?
error 502 bad gateway when download file angular 11?

Time:04-16

I work on download zip file from angular 11 .

I face issue when download Large files but small files not have any issue .

Large file i download have size 2.397 kb.

it will take 7 minutes to finish download but after 2 minute give me error 502 bad gateway.

it download file from local pc without any issue but when try to download file from remote server publish give me error 502 bad gateway .

so How to solve this issue and why I get this error ?

e {headers: n, status: 502, statusText: 'Bad Gateway', url: 'https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp', ok: false, …}
error: Blob
size: 1477
type: "text/html"
[[Prototype]]: Blob
headers: n
lazyInit: ƒ ()
lazyUpdate: null
normalizedNames: Map(0) {size: 0}
[[Prototype]]: Object
message: "Http failure response for https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp: 502 Bad Gateway"
name: "HttpErrorResponse"
ok: false
status: 502
statusText: "Bad Gateway"
url: "https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp"
[[Prototype]]: Object
constructor: ƒ e(e)
[[Prototype]]: Object

what i have tried

web api
[Route("ExportNxp")]
        public IActionResult ExportNxp(bool areIdentical)
        {
         
                if (areIdentical == false)
                {
                    return OK("Not Matched Excel");
                }
                else  
                {
                   
                return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));
              
                }

        }
service.ts
PostUploadzipNxp(file:any):Observable<any>
{
  formData.append('file', file,file.name);
  return this.http.post('https://pn.xxx.com:7072/api/Z2Delivery/ExportNxp/', formData,{observe: 'response', responseType: 'blob' });
}
component.ts
 this._dataService.PostUploadzipNxp(this.fileToUpload)
     .subscribe(blob => {
       saveAs(blob.body, this.fileToUpload?.name  '.zip');
      });

CodePudding user response:

By default, ASP.NET Core request time out is 2 minutes, and you can change it via KeepAliveTimeout in program.cs file

in .net core 6.0

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(t =>
{
  t.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(15);
});

in .net core 3.1

 public static void Main(string[] args)
 {
  CreateWebHostBuilder(args).Build().Run();
 }

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .ConfigureKestrel(o => { o.Limits.KeepAliveTimeout =  TimeSpan.FromMinutes(10); });
  • Related