Guna Shekar
Guna Shekar

Reputation: 133

How to upload a csv file using Swagger Open API 3.0?

I have given the following specification for csv file upload:-

requestBody:
        description: .csv file 
        content:
          application/csv:
            schema:
              type: string
              format: base64

I have also tried different types instead of application/csv, like multipart/form-data, text/csv etc. but none of them show a file upload option on the Swagger UI(also tried changing format to byte, binary, but no luck). The documentation mentions file upload only for images(which works fine).

Is there any way we can get the file upload option for csv or pdf files?

Upvotes: 1

Views: 9046

Answers (2)

Ritik Kumar
Ritik Kumar

Reputation: 1

paths:/upload:
 post:
   summary: Uploads a file.
   consumes:
     - multipart/form-data
   parameters:
     - in: formData
       name: upfile
       type: file
       description: The file to upload.

Upvotes: 0

Helen
Helen

Reputation: 97847

As of April 2020, Swagger UI shows the upload button only for application/octet-stream and image/ media types. There's an open issue to support file upload for other media types as well:
https://github.com/swagger-api/swagger-ui/issues/5636

As a workaround, you can try using application/octet-stream instead of application/csv.

Upvotes: 0

Related Questions