raghavginfocus
raghavginfocus

Reputation: 343

Download Excel file as a response from Open Api 3

I am editing in editor.swagger.io How can I download response from API locally which is a excel file? The API being used for converting json to Excel is written in python. My snippet -

responses:
        200:
          description: "JSON to Excel conversion succeeded"
          content:
            application/vnd.ms-excel:
              schema:
                type: string
                format: binary

I get server response of 200 saying

😱 Could not render this component, see the console.

In console the response headers are -

cache-control: public, max-age=0

content-length: 8515

content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

expires: Tue, 10 Dec 2019 15:14:55 GMT

I want to save excel file locally.

Upvotes: 2

Views: 9529

Answers (1)

raghavginfocus
raghavginfocus

Reputation: 343

Figured out that Content Disposition header has to be exposed in the python code for MIME types such as application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.

In python code you should have a line like this -

CORS(app,expose_headers=["Content-Disposition"])

If your MIME type is application/octet-stream then this isn't required but for other MIME types this may be required.

Upvotes: 1

Related Questions