Error 413 (request entity too large) occurs when Azure Functions reads the Base64 string.

Asked 2 years ago, Updated 2 years ago, 75 views


in Azure Functions (C#, Runtime.NET6, HttpTrigger) When receiving an Http Request (POST/Type JSON), the parameters of the body part are
A 413 error (request entity too large) occurs when the base 64 string (image itself encodes about 85KB).
Azure Functions uses a standard plan.

Desired behavior

I want to receive the Base64 string in Azure Functions in POST Request and display the contents in log.LogInformation.

HttpRequest

{
 "image": "Base64 format string~~(80KB)"
}

Azure Functions

public static async Task<IActionResult>Run(
        HttpTrigger (AuthorizationLevel.Function, "get", "post", Route=null) HttpRequest req,
        ILogger log)
    {
        // Build Count.
        log.LogInformation("BuiltNo.0011 AddInspectionRecord.cs");

        string requestBody = wait new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        string lBaseString=data.image;

        log.LogInformation(lBaseString);### I want to see Base64 string in this log

        return newOkObjectResult("test");

    }

c# http azure

2022-09-30 11:27

1 Answers

The questioner has left and doesn't seem to want to write down how it was solved.

So, I didn't answer the question of what I thought when I saw this thread, but I'll write it down below.

Some articles that google with azure function requestity too large show that CORS configuration avoids problems.

[FIXED] Azure function failing: "statusCode":413, "message": "request entity too large"
https://www.pythonfixing.com/2021/10/fixed-azure-function-failing-413-entity.html

I don't understand why CORS is involved, but I thought it would be good to try it.

All I can think of is whether the actual size of the JSON string I sent is too large.

By default, when a client sends a JSON string to an ASP.NET web service method, the length of the JSON string that can be sent to the server is limited to 102,400 characters.

In the ASP.NET MVC app, the character limit is the default value of 2,097 and 152 characters for the MaxJsonLength property of the JavaScriptSerializer class.

See the article below for more information.

MVC ignores maxJsonLength
http://surferonwww.info/BlogEngine/post/2013/08/07/asp-net-mvc-ignors-the-maxjsonlength-setting-in-web-config.aspx

I don't know Azure Functions, but there may be similar restrictions.


2022-09-30 11:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.