question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem when adding an api controller method with an IFormFile parameter

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
srollinetcommented, Apr 3, 2019

I can confirm that everything works now, thanks!

0reactions
RicoSutercommented, Apr 2, 2019

Please retest with v12.1.0 soon

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found