📜  在 send_file 之后烧瓶删除文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:42.389000             🧑  作者: Mango

代码示例1
@app.route('/files//download')
def download_file(filename):
    file_path = derive_filepath_from_filename(filename)
    file_handle = open(file_path, 'r')
    @after_this_request
    def remove_file(response):
        try:
            os.remove(file_path)
            file_handle.close()
        except Exception as error:
            app.logger.error("Error removing or closing downloaded file handle", error)
        return response
    return send_file(file_handle)