The Error
When I test with file size more than 28.6MB (e.g. 30MB) from swagger ui, I get the following error response:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at ec2-00-00-0-000.compute-1.amazonaws.com Port 80</address>
</body></html>
Project info
- Project type: dot net core web api (C#)
- Hosted on: aws (ec2)
What I've done so far
I added a web.config
file with the following content
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
I added the following to the Startup.cs
file
public void ConfigureServices(IServiceCollection services)
{
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<FormOptions>(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.MultipartBodyLengthLimit = int.MaxValue;
x.MultipartHeadersLengthLimit = int.MaxValue;
});
...
...
...
}
Test model class:
public class TestModel
{
public IFormFile TestFile { get; set; }
}
Test controller method:
[Route("uploadtest")]
[HttpPost]
[Consumes("multipart/form-data")]
public async Task<ActionResult> UploadTest([FromForm] TestModel fff)
{
return Ok();
}
Extra info
I do not get the error response when I run it on my local pc from visual studio (IIS Express).