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.

OpenAPI 3.0.1 upload/download file example

See original GitHub issue

Do you have an example of what an ASP.Net Core 3.0 API operation that uploads and downloads a file and what the OpenAPI 3.0.1 yaml should look like in order to properly generate a client using NSwag code generator?

I’ve tried every combination I can think of, and nothing seems to work. Either I get errors trying to deserialize to a FileContent type, or I get errors about not finding the Content boundary or else the client has random parameters that aren’t used or a myriad of other issues. At this point, my yaml is identical to what’s on the OpenApi documentation page, but this doesn’t work, either: https://swagger.io/docs/specification/describing-request-body/file-upload/ I just need a working example to go off of so I can stop guessing.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
dtaalberscommented, Feb 10, 2020

On your client side, if you would replace the FileParameter/Blob into FormData and send the file as below, the IFormFile would get filled in.

const formData = new FormData();
formData.append('file', fileObj)

Are you suggesting this to me? If so, thanks for the reply! But I know that the client needs to have FormData. But I don’t want to do that manually every time after I generate the client. The trick is to get nswag to do that. But the solution that I used for dotnet core 2.x and 4.x swashbuckle, doesn’t work for dotnet core 3.x and swashbuckle 5.x.

4reactions
dellel-firascommented, Feb 11, 2020

Hello, I had exactly the same issue, so I did like @mahinthan suggested, but it was not enough, in the request I got payload instead of formData, so the missing part of the solution is to delete the content type which have this value “multipart/form-data” from the generated code and it worked well "Content-Type": "multipart/form-data" But it’s not really practice to change manually a generated code, that’s why I added some code to the useTransformOptionsMethod remove the content type when it is equal to “multipart/form-data” Hope that it helps, and that will be fixed soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File Upload
In OpenAPI 3.0, you can describe files uploaded directly with the request content and files uploaded with multipart requests. Use the requestBody keyword...
Read more >
OpenAPI 3.0 - how to define file download operation correctly
I use online Swagger Editor with OpenAPI 3.0 and I have to create a definition file download. I develop server-side and a customer...
Read more >
A Sample OpenAPI 3.0 File to Get Started
Familiarize yourself with the new OpenAPI specification version 3.0 by looking over this example file, with an analysis and thoughts from ...
Read more >
OpenAPI 3.0 Tutorial | SwaggerHub Documentation
In this tutorial, we will write a simple API definition in the OpenAPI 3.0 format. If you are using OpenAPI 2.0 (Swagger 2.0),...
Read more >
Post File in Swagger OpenAPI V3.0 and V2.0 examples
Post File in Swagger OpenAPI V3.0 and V2.0. Upload single or multiple files in Swagger UI using OpenAPI 3.0 or V2.0 specifications with...
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