Aspnetcore: The introduction of FormFileValueProvider broke the documented large file upload

Created on 27 Sep 2019  路  5Comments  路  Source: dotnet/aspnetcore

Describe the bug

This bug tries to tie a couple of issues and provide some search terms.

9510 and #12847 introduced FormFileValueProviderFactory in the ResourceExecutingContext's ValueProviderFactories.

On the other hand, the 2.2 documentation for streaming file upload describes which ValueProviderFactories to remove in order to make large file uploads work.

The documentation team is already updating the docs: https://github.com/aspnet/AspNetCore.Docs/issues/13344

Should this be part of the breaking changes in 3.0?

To Reproduce

Run the documentation's 2.2 code on 3.0 and notice that the request fails with

System.IO.InvalidDataException: Multipart body length limit 134217728 exceeded.
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.UpdatePosition(Int32 read)
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.ModelBinding.FormFileValueProviderFactory.AddValueProviderAsync(ValueProviderFactoryContext context, HttpRequest request)
   at Microsoft.AspNetCore.Mvc.ModelBinding.CompositeValueProvider.CreateAsync(ActionContext actionContext, IList`1 factories)
   at Microsoft.AspNetCore.Mvc.ModelBinding.CompositeValueProvider.CreateAsync(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
[鈥

Expected behavior

Streaming file uploads should work.

To fix

RemoveType the FormFileValueProviderFactory in the resource filter attribute as well.

Docs area-mvc

All 5 comments

Thanks @Tragetaschen. Does updating the filter to remove the additional value provider suffice?

Yes, removing this additional factory

         {
             var factories = context.ValueProviderFactories;
             factories.RemoveType<FormValueProviderFactory>();
+            factories.RemoveType<FormFileValueProviderFactory>();
             factories.RemoveType<JQueryFormValueProviderFactory>();
         }

re-enables my software update (~230MiB) upload again.

@guardrex any chance you could incorporate this after you're done merging your other PR?

Yes ... it was left as a comment on https://github.com/aspnet/AspNetCore.Docs/issues/13344#issuecomment-535728972 for the 3.0 updates to the File Upload topic.

Let's use the other docs issue to track addressing this. This is a known change, and updating the docs would be the way to go.

Was this page helpful?
0 / 5 - 0 ratings