How to change downloading name in flask?

前端 未结 4 2101
名媛妹妹
名媛妹妹 2021-02-18 17:06

I have a small project which has to response some files. I know that using nginx will be better decision but that files a really small.

Part of my program:

4条回答
  •  忘了有多久
    2021-02-18 17:30

    In some cases the filename is still not visible. To have it for sure you should set "x-filename" header and to expose this header.

    from flask import send_file
    response = send_file(absolute_image_path, mimetype='image/jpeg', attachment_filename=name, as_attachment=True)
    response.headers["x-filename"] = name
    response.headers["Access-Control-Expose-Headers"] = 'x-filename'
    return response
    

提交回复
热议问题