下载 Excel 文件作为对打开 Api 3 的响应

Download Excel file as a response from Open Api 3

我正在编辑editor.swagger.io 如何从 API 本地下载 excel 文件的响应?用于将json转换为Excel的API写在python中。 我的片段 -

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

我收到服务器响应 200 说

Could not render this component, see the console.

在控制台中,响应 headers 是 -

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

我想在本地保存 excel 文件。

发现内容处置 header 必须在 python 代码中针对 MIME 类型公开,例如 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet。

在 python 代码中你应该有这样一行 -

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

如果您的 MIME 类型是 application/octet-stream,那么这不是必需的,但对于其他 MIME 类型,这可能是必需的。