Reputation: 1
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
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