I'm trying to upload a folder of size 543 MB using IIS express server and ASP.NET core backend. The upload is initiated by an ajax call. If I split the folder into 100 MB chunks and upload these 100 MB chunks from the front-end everything works fine. But as pointed out here Can we split big ajax calls into multiple smaller calls to load data faster? splitting and making multiple calls has no evident advantage and might end up being a liability.
So now I'm trying to upload the folder as one ajax call. The problem is that the upload starts and I can see it progressing in the progress bar but after like 30% upload I get a Http Status code 500 from the server.
The server gives the following error:
Exception thrown: 'System.IO.InvalidDataException' in System.Private.CoreLib.dll
From what I understand this issue is related to file size limits imposed by IIS and ASP.NET core. To remedy this I have added the following code to my solution but no success.
UploadController.cs
[HttpPost]
[RequestSizeLimit(1073741824)]
[RequestFormLimits(MultipartBodyLengthLimit = 1073741824)]
public async Task<ActionResult> PostAsync(){
await Request.ReadFormAsync();
System.Diagnostics.Debug.WriteLine(Request.Form.Files.Count);
return Ok("Files uploaded.");
}
Web.Config
<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- Handle requests up to 2 GB -->
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
StartUp.cs
services.Configure<KestrelServerOptions>(options => { options.Limits.MaxRequestBodySize = null; });
services.Configure<FormOptions>(options =>
{ options.MultipartBodyLengthLimit = 2147483648;
options.ValueLengthLimit = 1073741824;
options.MultipartHeadersLengthLimit = 1073741824;
});
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = null;
});
The startup file has other configurations of course but these are what I added to solve this issue.
Thanks for the help in advance!!
PS : Let me know if any other information is required.