10

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>
Adam Smith
  • 101
  • 1
  • 3
  • Are you hosting on IIS? If yes, did you try to put this into your web.config to see if it works? – Fabricio Koch Oct 26 '16 at 15:44
  • 1
    What kind of upload is it? There's only a built in limit for Forms and multipart. https://github.com/aspnet/Performance/blob/2a1621d2c5dc1ab1d2ed280866f09cc7e5a81589/testapp/MultipartPOST/MultipartPOST/Startup.cs#L22 – Tratcher Oct 26 '16 at 17:03

2 Answers2

5

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

Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55
2

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.

Will Ray
  • 10,621
  • 3
  • 46
  • 61