0

I have a task to allow uploads from an internal application that's built in .net5 razor pages of greater than 2gb per file. I have changed all the settings in the web.config and on server to allow these files to upload but still am greeted with a 400 error when trying.

<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>

<requestFiltering>
      <requestLimits maxAllowedContentLength="3147001541" />
    </requestFiltering>

I am using the following to upload the files

var path = Path.Combine(targetFileName, UploadedFile.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await UploadedFile.CopyToAsync(stream);
            }

then after that it just saves the location in the DB of where that file was copied.

Dark Daskin
  • 1,308
  • 1
  • 13
  • 22
TheDizzle
  • 1,534
  • 5
  • 33
  • 76
  • 2
    `maxRequestLength` is in kB. 20480kB is 20MB. That is considerably smaller than 2GB. – Heretic Monkey Mar 23 '21 at 19:58
  • This answer is for .NET Core, but since .NET 5 is its successor, it might apply to your problem as well: [Increase upload file size in Asp.Net core](https://stackoverflow.com/q/38698350/87698) – Heinzi Mar 23 '21 at 20:09

1 Answers1

0

system.web settings are only used by ASP.NET (not Core). In ASP.NET Core you change the limit for your action by adding the RequestSizeLimitAttribute or DisableRequestSizeLimitAttribute. Additionally you will likely need to increase form data limit by adding RequestFormLimitsAttribute.

MVC:

[RequestSizeLimit(3147001541)]
[RequestFormLimits(MultipartBodyLengthLimit = 3147001541)]
public async Task<IActionResult> Upload(IFormFile file)
{
    // ...
}

Razor Pages:

@attribute [RequestSizeLimit(3147001541)]
@attribute [RequestFormLimits(MultipartBodyLengthLimit = 3147001541)]

See documentation and this question for details.

Dark Daskin
  • 1,308
  • 1
  • 13
  • 22