IFormFile binding error
See original GitHub issueDescribe the bug
I have a model with IFormFIle property and other simple type properties.It could pass to the controller with [ApiController] and [FromForm] successfully.But If I only pass IFormFile property in model,it could not pass data to controller.I find a solution,when I remove [ApiController] and [FromForm],it works.
To Reproduce
using asp.net core 3.1
Model:
public class ProductImageDetailsDto
{
public IFormFile ProductImage { get; set; }
public bool IsDefaultImage { get; set; }
}
Controller:
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
[HttpPut("UpdateProductImagesByProductId/{id}")]
public async Task<IActionResult> UpdateProdutImagesByProductId(Guid id,[FromForm]List<ProductImageDetailsDto> productImages)
{
return Ok();
}
}
SO Reference:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Problem with model binding in file input type
I'm working on an Asp.Net Core MVC project. In my model, I have an IFormFile property. When I use a simple input tag...
Read more >Model Binding in ASP.NET Core
Learn how model binding in ASP.NET Core works and how to customize its behavior.
Read more >Upload files in ASP.NET Core
ASP.NET Core supports uploading one or more files using buffered model binding for smaller files and unbuffered streaming for larger files.
Read more >File uploads in ASP.NET Core - About me and my site.
When uploading files using model binding and the IFormFile interface, ... The following error indicates your file upload exceeds the server's configured ......
Read more >Upload Single Or Multiple Files In ASP.NET Core Using ...
In this article, we are going to see how to upload files in asp.net core web application and store in root directory of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mkArtakMSFT I have create a github repo here: https://github.com/daping123/ModelBindingProj
When you post only ProductImage in postman,I will receive data count=0. When you post both ProductImage and IsDefaultImage,I will receive the correct data.
Why?Does IFormFile run the different pipeline in model binding?And my workaround is that,when I remove [ApiController] and [FromForm], I could pass ProductImage without IsDefaultImage.For my workaround,i am also confused,why i can’t add [FromForm]?
And I find if I receive Model instead of List<Model> in backend.Using [FromForm] is OK.
I have spent the last 3 days looking to find how others have solved this problem but nothing out there works. Guess it is bug. When will this be released to production please?