Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask remove file after send_file

@app.route('/files/<filename>/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)
Comment

PREVIOUS NEXT
Code Example
Python :: python diagonal sum 
Python :: cd in python 
Python :: unittest skip 
Python :: check if there are duplicates in list 
Python :: convert matplotlib figure to cv2 image 
Python :: twitter api v2 python tweepy 
Python :: find factorial in python 
Python :: python pandas give column names 
Python :: dataframe time index convert tz naive to tz aware 
Python :: Python datetime to string using strftime() 
Python :: how to import numpy in python 
Python :: how to convert a list to dataframe in python 
Python :: convert list to dataframe 
Python :: one line if statement without else 
Python :: python counting dictionary 
Python :: how to scrape multiple pages using selenium in python 
Python :: python get all combinations of list 
Python :: python list fill nan 
Python :: python substring 
Python :: dictionary with list as value py 
Python :: dummy variables pandas 
Python :: python mettre en minuscule 
Python :: pyspark print a column 
Python :: opencv shift image python 
Python :: plot pil image colab 
Python :: finding path of a module in python 
Python :: run for loop inside pdb 
Python :: difference between set and tuple in python 
Python :: Making a txt file then write 
Python :: Python program to implement linear search and take input. 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =