I want to upload a file with a size of round about 80Mb to my controller:
[HttpPost("UploadJar")]
[RequestFormLimits(MultipartBodyLengthLimit = 104857600)]
public ActionResult UploadJar([FromForm]IFormFile file)
{
if (file is not { Length: > 0 })
{
return BadRequest();
}
var filePath = $"{Path.GetTempPath()}{Guid.NewGuid()}.jar";
using (var stream = System.IO.File.Create(filePath))
{
file.CopyTo(stream);
}
if (ValidateJarFile(filePath) == false)
{
System.IO.File.Delete(filePath);
return BadRequest();
}
HttpContext.Session.SetString("jarFileTempPath", filePath);
return Ok();
}
My Startup
class contains the following configuration:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 120000000; // 120Mb
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = 120000000; // 120Mb, if don't set default value is: 30 MB
});
And the profiles I use with Jetbrains Rider are:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASP.NETCoreWebApplication": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
When I use the profile ASP.NETCoreWebApplication
everything is fine, but if I use the profile IIS Express
, I get a 413 (file too large) error when uploading a file.
Can anyone explain this to me?
CodePudding user response:
In web. config under System.WebServer you need to put this.
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
see the following link - Default Limits <limits> for IIS Express