Azure App Service returns internal server errors with file upload API

Sreejith MS 5 Reputation points
2023-09-15T10:01:02.3133333+00:00

I have identified an issue within Azure App Service that results in internal server errors when working with file upload APIs. To demonstrate this issue, I created a sample .NET API.

Repo: https://github.com/sreejith-ms/WeatherForecast-AppServiceIssue

API: POST /WeatherForecast/maxsizelimit

This is a multipart file upload API that has a maximum request size limit of 2MB.

When I attempted to upload files ranging in size from over 2MB to approximately 14MB, the API responded correctly with a 400 Bad Request error, indicating that the request body was too large. However, when attempting to upload files larger than 14MB, the App Service started responding with internal server errors (500/502). The size of 14MB is where I mostly encounter the issue; however, the size may vary based on your network bandwidth.

User's image

Interestingly, the App Service logs clearly indicate that the container responded with a 400 bad request error.

2023-09-15T06:21:09.984488565Z: [INFO]  [06:21:09 INF] Executing endpoint 'WebApi.Controllers.WeatherForecastController.MaxSizeLimit (WebApi)'
2023-09-15T06:21:09.984495065Z: [INFO]  [06:21:09 INF] Route matched with {action = "MaxSizeLimit", controller = "WeatherForecast"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult MaxSizeLimit(Microsoft.AspNetCore.Http.IFormFile) on controller WebApi.Controllers.WeatherForecastController (WebApi).
2023-09-15T06:21:09.995466589Z: [INFO]  [06:21:09 INF] Executing BadRequestObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.
2023-09-15T06:21:10.002687405Z: [INFO]  [06:21:10 INF] Executed action WebApi.Controllers.WeatherForecastController.MaxSizeLimit (WebApi) in 19.1306ms
2023-09-15T06:21:10.003785308Z: [INFO]  [06:21:10 INF] Executed endpoint 'WebApi.Controllers.WeatherForecastController.MaxSizeLimit (WebApi)'
2023-09-15T06:21:10.005613012Z: [INFO]  [06:21:10 INF] Request finished HTTP/1.1 POST http://webapi20230915103952.azurewebsites.net/WeatherForecast/maxsizelimit multipart/form-data;+boundary=--------------------------569753000962407339218899 12583133 - 400 - application/problem+json;+charset=utf-8 27.6253ms

It's worth noting that the issue does not seem to be related to the file size (14MB) because the same file uploads successfully using another API that does not have any request size limits, relying on the default Kestrel limit (around 30MB).

API: POST /WeatherForecast

If you attempt to upload files larger than 30MB, you will encounter the same internal server error.

To confirm that this is indeed an issue with the Azure App Service, I deployed the same application to Azure Container Apps and the upload APIs worked as expected without any issues.

You can try out the sample application in the following links:

App service: https://webapi20230915103952.azurewebsites.net/swagger/index.html

Container Apps: https://webapi-containerapp-20230915112.jollyground-642ed217.centralus.azurecontainerapps.io/swagger/index.html

File generator: https://fastest.fish/generate-file

P.S.: The issue may not be reproducible when testing from a high network bandwidth connection. In such cases, you can try using browser network throttling. I used Firefox throttling preset: WIFI (download: 30 Mbps, upload: 15 Mbps)

4FChjztAV3

Ap4NeeAbWG

wNWr157GHu

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,244 questions
{count} votes