How can I set maximum upload size for an ASP.NET CORE
application?
In the past I was able to set it in web.config
file like this:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
You need to add/update the values of "executionTimeout", "maxRequestLength" & "maxAllowedContentLength" properties if not already added in the "Web. config" file, as shown below. executionTimeout -> The amount of time required to process your request on the web server; The value is provided in seconds.
You will need to right click your project in Solution Explorer, then select Add then New Item from the Context menu. Then from the Add New Item Dialog window, select Web Configuration File option and click Add Button. Finally, in the Web. Config file, set the maxAllowedContentLength setting to 100 MB as shown below.
After our Web API loaded, we can come to postman tool and using POST method we can send a request to Web API. We must choose “form-data” in the body part and choose “File” as type. We can click the “Send” button now. After some time, we will get a result.
IIS limits the upload file size by default to 30000000 bytes which is approximately 28.6 MB. This can also be caused by a size restriction by the SMTP server configuration.
Two ways to do that:
1.Using application wise settings - in the > configure services method.
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 52428800;
});
2.Using RequestFormSizeLimit attribute - for specific actions. - It is not yet available in official package Unofficial
You can configure the max limit for multipart uploads in the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 52428800;
});
services.AddMvc();
}
You can also configure the MaxRequestBufferSize
by using services.Configure<KestrelServerOptions>
, but it looks like this is going to be deprecated in the next release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With