1@app.route('/files/<filename>/download')
2def download_file(filename):
3 file_path = derive_filepath_from_filename(filename)
4 file_handle = open(file_path, 'r')
5 @after_this_request
6 def remove_file(response):
7 try:
8 os.remove(file_path)
9 file_handle.close()
10 except Exception as error:
11 app.logger.error("Error removing or closing downloaded file handle", error)
12 return response
13 return send_file(file_handle)
14