Search code examples
c#asp.net-corerazor-pageslarge-files

Razor Pages .Net Core - cannot upload large Files / Videos


I am trying to 'upload' a video file in to my application and pass it to the database. I am able to handle pictures quite nicely however as soon as I try larger / video files I am getting a Status: 400 error code when a Submit is made.

enter image description here

I put a break point on the OnPostAsync method in code behind but it doesn't get hit. I just have a standard Input --> Type: File:

enter image description here

and from seeing a few mentions online I have manually added a web.config file to the project and added the following:

enter image description here

However I still get the 400 error if I attempt to upload a large file. I notice in the actual call it should allow the mime type:

enter image description here

As per other advice I have also tried adding the following to the

enter image description here

but get the following:

enter image description here

And also on the model that is being populated with the large file data:

enter image description here

Still the same error.

I would be interested to hear peoples suggestions on what could be causing my error.


Solution

  • I have managed to get this working eventually by adding the following to the Startup.cs file:

    enter image description here

    Code:

            services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = int.MaxValue;
                x.MultipartBodyLengthLimit = int.MaxValue;
                x.MultipartHeadersLengthLimit = int.MaxValue;
            });
    
            services.Configure<KestrelServerOptions>(options =>
            {
                options.Limits.MaxRequestBodySize = int.MaxValue;
            });
    

    Now I am able to load large files as expected.