下载Excel文件作为Open Api 3的响应

问题描述 投票:0回答:1

我正在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条服务器响应

😱无法呈现此组件,请参见控制台。

在控制台中,响应标题为-

cache-control:public,max-age = 0

内容长度:8515

内容类型:application / vnd.openxmlformats-officedocument.spreadsheetml.sheet

过期:周二,2019年12月10日15:14:55 GMT

我想在本地保存Excel文件。

swagger swagger-ui openapi swagger-editor
1个回答
0
投票

[发现Content Disposition标头必须在MIME类型(例如application / vnd.openxmlformats-officedocument.spreadsheetml.sheet)的python代码中公开。

在python代码中,您应该有这样的一行-

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

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

© www.soinside.com 2019 - 2024. All rights reserved.