【问题标题】:Change the downloading file name in Flask更改 Flask 中的下载文件名
【发布时间】:2021-09-06 07:14:39
【问题描述】:

我创建了一个返回 tar 文件的 api。当我尝试大摇大摆地下载它时,它会以一些随机的垃圾名称下载,例如"application_octet-stream_generate_blob_https___editor.swagger.io_9ecd1754-0f85-4ed7-97ca-816bb446e5e2",文件名应该是migration.tar

这是我的代码

response = send_file(fpath, as_attachment=True, mimetype="application/octet-stream",download_name="migration.tar")

return response

当我尝试在邮递员中下载它时,它工作正常 提前谢谢..

【问题讨论】:

标签: python flask swagger


【解决方案1】:

您可以使用参数attachment_filename指定文件名。

return send_file(
    fpath, 
    mimetype="application/octet-stream", 
    as_attachment=True, 
    attachment_filename="migration.tar"
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多