billbogaiv / hybrid-model-binding

Provides the ability to bind models using both ModelBinder and ValueProvider in ASP.NET Core.
MIT License
104 stars 19 forks source link

MultipartFormData to IFormFile #35

Closed vadim-bondaruk closed 5 years ago

vadim-bondaruk commented 5 years ago

Hi, is it possible bind multipart form data file to IFormFile model property?

billbogaiv commented 5 years ago

Not right now. Currently, the library uses .NET Core's FormValueProvider. Taking a look at the source, it stores key-values as a dictionary of <string, StringValues>. It's mainly intended to access non-file things.

Ref. https://github.com/aspnet/AspNetCore/blob/7a26d27e8b7f67a1ac80532e5872bfde6c28f952/src/Mvc/Mvc.Core/src/ModelBinding/FormValueProvider.cs Ref. https://github.com/aspnet/AspNetCore/blob/fc9e48877c75562af1d3879a57694f55d5685397/src/Http/Http/src/FormCollection.cs#L50

I toyed with the idea of deriving from that provider and creating something that would read the form's File-collection. This might also require creating a custom TypeConverter–these are currently used internally to convert string-values in the request to simple property-types on the model (i.e. int, bool, etc). Maybe someday, but not on my RADAR.

I'm closing this issue, but keep subscribed to notifications and if it does get implemented, I'll reference this issue.

billbogaiv commented 4 years ago

37 has an implementation for parsing files. It's brute-force at the moment, but gets the job done.