Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max upload size for ASP.MVC CORE website

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>
like image 250
Adam Smith Avatar asked Oct 26 '16 14:10

Adam Smith


People also ask

How can increase upload file size in ASP.NET MVC?

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.

How do I upload a large file to .NET core?

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.

How do you upload a 5 GB file through your spa to Web API?

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.

What is max upload size IIS?

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.


2 Answers

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

like image 187
Vishwa Ratna Avatar answered Sep 28 '22 11:09

Vishwa Ratna


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.

like image 39
Will Ray Avatar answered Sep 28 '22 13:09

Will Ray