I have an ASP.NET Core 6/7 Web API with an endpoint that uploads files using multipart/form-data. I want to allow files of 50 MB or larger.
I'm currently testing with cURL:
curl -X POST "https://xxxx/v1/Cons/attachments" \
-H "accept: text/plain" \
-H "x-api-key: <api-key>" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: multipart/form-data" \
-F "[email protected];type=application/pdf" \
-F "userId=xxx" \
However, when I try to upload larger files, I get:
HTTP Error 413.1 – Request Entity Too Large
What I've tried:
Kestrel settings in
Program.cs:webBuilder.ConfigureKestrel(options => { options.Limits.MaxRequestBodySize = 524288000; // 500 MB });Controller attributes:
[RequestSizeLimit(524288000)] [RequestFormLimits(MultipartBodyLengthLimit = 524288000)] [HttpPost("attachments")] public async Task<IActionResult> Upload([FromForm] ConstructionAttachmentModel model) { // handle file }Web.config(for IIS layer, after publishing):<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="524288000" /> </requestFiltering> </security> </system.webServer>Azure App Service application setting:
Key: ASPNETCORE_MAXREQUESTBODYSIZE Value: 524288000
Question
After all these changes, my API still returns 413.1 for large uploads on Azure app service.
How can I reliably allow file uploads > 50 MB in an ASP.NET Core 6/7 Web API on Azure?
Additional info:
- ASP.NET Core 6/7
- Web API deployed to Azure App Service
- Testing with cURL and Postman
- Local Kestrel upload works fine