DEV Community

Cover image for Azure Functions Tips: change the limit for the size of body in a function
Massimo Bonanni
Massimo Bonanni

Posted on

Azure Functions Tips: change the limit for the size of body in a function

When you implement an Http Trigger Function that manages a request with a body, you have a size limit for the body itself. The default value for this limit is 100Mb (actually 104857600 bytes and you can read it in the Http Trigger documentation).

You can manage this limit using the Function App configuration. In particular, you can add the setting FUNCTIONS_REQUEST_BODY_SIZE_LIMIT to set the maximum number of bytes you support in a single Http request.

Just to test how this setting works, use the following simple function:

[FunctionName("PostSomething")]
public IActionResult PostSomething(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = "post")] HttpRequest req,
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    return new OkResult();
}
Enter fullscreen mode Exit fullscreen mode

You can do it also in your machine:

  • Add the config to your local setting file of the Function project:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_REQUEST_BODY_SIZE_LIMIT": 100
  }
}
Enter fullscreen mode Exit fullscreen mode
  • Run the project:

The log of the function runtime

  • Make a POST Http request (for example using curl):
curl -X POST http://localhost:7077/api/post --data "This is the payload of the request and its size is more than 100 bytes. The function should throw an exception!!"
Enter fullscreen mode Exit fullscreen mode
  • The function's log should display the error related to the size of the body:

The Request Body Too Large error throws by the function

You can have the same behavior if you set the application setting value in a Function App on Azure:

The application settings of the Azure Function

and then you can test the function:

The test UI of the Azure Portal for an Azure Function

having the error:

The "request body too large" error in the Azure Function monitor page

Top comments (0)