Overriding Request Form max upload limit
From @Tratcher on May 27, 2016 18:33
From @Ryuuke on May 27, 2016 18:30
Hello, I encountered this error when uploading large file (~200MB).
An unhandled exception occurred while processing the request. Multipart body length limit 134217728 exceeded at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.UpdatePosition(Int32 read)
I already tried to modify my web.config file : httpRuntime maxRequestLength="1073741824" executionTimeout="300000" and requestLimits maxAllowedContentLength="1073741824"
but still, I get the same error.
I'm using the RC2 version, is there a way to override that limit ?
Copied from original issue: aspnet/KestrelHttpServer#891
Copied from original issue: aspnet/HttpAbstractions#641
From @Tratcher on May 27, 2016 18:38
There are limits on the request form. Where are you trying to read the Form, an MVC Controller/Action?
The limits can be adjusted per action like this: https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.FileUpload/Controllers/RequestFormLimitsController.cs#L19
Or for the whole app like this (but don't do this just for one file): https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.FileUpload/Startup.cs#L34
From @davidfowl on May 27, 2016 18:40
@Tratcher @Eilon @kichalla should that filter be built into mvc?
From @Tratcher on May 27, 2016 18:42
@rynowak Probably.
From @Tratcher on May 27, 2016 18:43
https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.FileUpload/Filters/RequestFormSizeLimitAttribute.cs
From @Ryuuke on May 27, 2016 19:7
Hey, thanks for your reply, yeah i'm trying to read the form from the an MVC action, it was the MultipartBodyLengthLimit property inside the FormOptions that I updated to a larger value than the default and It Worked well.
From @victorhurdugaci on July 6, 2016 22:16
This is something that should be in MVC. cc @kichalla @rynowak
From @Eilon on July 7, 2016 1:52
Is this the same as https://github.com/aspnet/Mvc/issues/481?
From @Tratcher on July 7, 2016 2:21
Not quite, this is specific to forms.
We should revisit what exactly we want to do here.
What am I missing? We added upload limits to kestrel by default, and also added an override to MVC in a sample
I think the proposal was to add a MVC filter to set the available form options here https://github.com/aspnet/HttpAbstractions/blob/8b3c308c226dd61532e543697d9d35bb94aba823/src/Microsoft.AspNetCore.Http/Features/FormOptions.cs. There is a sample in Entropy that illustrate this mentioned above but I think the discussion was whether we should polish that and ship it.
Upgraded my project to latest versions 1.1.1 along with the tooling upgrade in VS2017. The work around mentioned doesn't seem to work anymore. When I'm debugging I can see the options code gets run and the values are updated. The controller just doesn't seem to recognize the change.
Keep getting "Multipart body length limit 16384 exceeded." even though I have this in my startup.
services.Configure<FormOptions>(options =>
{
options.ValueLengthLimit = int.MaxValue;
options.MultipartBodyLengthLimit = long.MaxValue;
});
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
@JasonRowe, I ran into that issue earlier today, I upgraded a project to 1.1.1 yesterday.
For me I believe having the RequestFromSizeAttribute on the method fixed the problem. I haven't had time to dig in and actually figure out what fixed it.
Heres an example:
[HttpPost("api/[controller]/upload")]
[RequestFormSizeLimit(500, 1024 * 1024 * 25)] //500 - ValueCount Limit, 25 MB MaxBodyPartLengthLimit
public async Task
Also tried adding a form attribute with no luck. Nothing I do seems to effect the MultipartBodyLengthLimit. Anyone have a work around?
Here was what my attribute was doing:
public RequestFormSizeLimitAttribute(int valueCountLimit, long multipartBodyLengthLimit)
{
_formOptions = new FormOptions()
{
ValueCountLimit = valueCountLimit,
MultipartBodyLengthLimit = multipartBodyLengthLimit
};
}
/cc @Tratcher @halter73 - what's the right setting for this?
I also tried the "DisableFormValueModelBindingAttribute" attribute from these old docs and it didn't help.
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads
https://raw.githubusercontent.com/aspnet/Docs/master/aspnetcore/mvc/models/file-uploads/sample/FileUploadSample/Filters/DisableFormValueModelBindingAttribute.cs
@rynowak Here are the Kestrel limits that can be configured today.
While you can set absolute limits for the request line and request headers sizes, there is none for the request body. The MaxRequestBufferSize only limits the number of request body bytes that can sit in Kestrel's internal buffers without the app reading them before back pressure is applied.
Not very helpful but suddenly I can't recreate my issue. I did change some settings that made my virtual machine run faster (added additional CPU's). Now I don't appear to need any settings in the startup and the same file works fine via the same form without changes.
/cc @Tratcher did you have any thoughts on this?
Not if he can't reproduce it. It would be nice to make the sample filter/attribute a shipping thing.