Bhavan Kamble
Bhavan Kamble

Reputation: 1

.Net Core API File Upload . Failed to read the request form. Multipart body length limit 16384 exceeded

Subsequent request to the file upload for .net core api fails but works for the very first request via postman.

Error : multipart body length limit 16384 exceeded.

Note : Working fine in local getting issue only in IIS

Added below code in startup.cs

services.Configure<FormOptions>(options => { options.ValueCountLimit = 10; //default 1024 options.ValueLengthLimit = int.MaxValue; //not recommended value options.MultipartBodyLengthLimit = long.MaxValue; //not recommended value });

Upvotes: 0

Views: 4550

Answers (1)

Ramin Azali
Ramin Azali

Reputation: 283

For application running on IIS:

services.Configure<IISServerOptions>(options =>
{
    options.MaxRequestBodySize = int.MaxValue;
});

For application running on Kestrel:

services.Configure<KestrelServerOptions>(options =>
{
    options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set 
  //default value is: 30 MB
});

Form's MultipartBodyLengthLimit:

services.Configure<FormOptions>(options =>
{
    options.ValueLengthLimit = int.MaxValue;
    options.MultipartBodyLengthLimit = int.MaxValue; // if don't set 
    //default value is: 128 MB
    options.MultipartHeadersLengthLimit = int.MaxValue;
});

Adding all the above options will solve the problem related to the file upload with a size of more than 30.0 MB.

I hope its help.

Upvotes: 3

Related Questions