【发布时间】:2021-05-30 21:07:41
【问题描述】:
错误
当我从 swagger ui 测试文件大小超过 28.6MB(例如 30MB)时,我收到以下错误响应:
<!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>
项目信息
- 项目类型:dot net core web api (C#)
- 托管在:aws (ec2)
到目前为止我做了什么
我添加了一个web.config 文件,内容如下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
我在Startup.cs 文件中添加了以下内容
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;
});
...
...
...
}
测试模型类:
public class TestModel
{
public IFormFile TestFile { get; set; }
}
测试控制器方法:
[Route("uploadtest")]
[HttpPost]
[Consumes("multipart/form-data")]
public async Task<ActionResult> UploadTest([FromForm] TestModel fff)
{
return Ok();
}
额外信息
当我从 Visual Studio (IIS Express) 在本地电脑上运行它时,我没有收到错误响应。
【问题讨论】:
标签: c# .net-core amazon-ec2 file-upload