Problem when adding an api controller method with an IFormFile parameter
See original GitHub issueHi,
I tried to add a new method in one of my controller. This method takes an IFormFile
parameter
As soon as I add this method, there is a new consumes
array in swagger.json which only contains the value "multipart/form-data"
Problem is when I generate the ts client, all the methods try to send multipart/form-data
I tried to create a simplified repro project, but I cannot reproduce it 😦 Any idea about the cause?
This is the new controller
[ApiVersion("1")]
public class ConfigurationController : ApiControllerBase
{
[HttpPost, DisableRequestSizeLimit]
public void UploadFile(IFormFile file)
{
}
}
swagger.json before I add the controller (there is no consumes array) Note: in my repro project, there is always a consumes array. Do you know what can prevent it to appear?
{
"x-generator": "NSwag v11.18.6.0 (NJsonSchema v9.10.67.0 (Newtonsoft.Json v11.0.0.0))",
"swagger": "2.0",
"info": {
"title": "My Title",
"version": "1.0.0"
},
"produces": [
"text/plain",
"application/json",
"text/json"
],
...
}
swagger.json when I add the new controller
{
"x-generator": "NSwag v11.18.6.0 (NJsonSchema v9.10.67.0 (Newtonsoft.Json v11.0.0.0))",
"swagger": "2.0",
"info": {
"title": "My Title",
"version": "1.0.0"
},
"consumes": [
"multipart/form-data"
],
"produces": [
"text/plain",
"application/json",
"text/json"
],
...
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to upload an IFormFile with additional parameters
Using postman I've tried setting the Content-Type to multipart/form-data , to no avail. Is this approach somehow possible, or do I need to...
Read more >How to call web API with iformfile and another string ...
You're sending the local path of the file, rather than the content of the file. That won't work - the server has no...
Read more >Create web APIs with ASP.NET Core
The [ApiController] attribute applies an inference rule for action parameters of type IFormFile and IFormFileCollection. The multipart/form-data ...
Read more >Upload files in ASP.NET Core
IFormFile can be used directly as an action method parameter or as a bound model property. The prior example uses a bound model...
Read more >Using ASP.NET Core 7 Minimal APIs: Request Filters ... - InfoQ
Uploading a file to an API endpoint is now as simple as adding an IFormFile parameter to the endpoint method.
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
I can confirm that everything works now, thanks!
Please retest with v12.1.0 soon