How to increase request length to upload large files in .NET Core 6?

Forums .NET CoreHow to increase request length to upload large files in .NET Core 6?
Staff asked 1 year ago

I have developed an ASP.NET Core Web API which is used to upload files. I am testing the API through postman. When I try to upload a file whose size is more than 28 MB it throws a request length exceeded error.

How to increase request length globally for IIS express and Dotnet CLI?

Answers (1)

Add Answer
Staff answered 2 months ago

After a lot of research, I found this and it works for me.

//IIS

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

//Kestrel
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = int.MaxValue;
});

just add these pieces of code in your Program.cs

Subscribe

Select Categories