How to rename uploaded file in Flask Web Framework How to rename uploaded file in Flask Web Framework flask flask

How to rename uploaded file in Flask Web Framework


Answer on your question exist in http://pythonhosted.org/Flask-Uploads/

save(storage, folder=None, name=None)

Parameters:
storage – The uploaded file to save.
folder – The subfolder within the upload set to save to.
name – The name to save the file as. If it ends with a dot, the file’s extension will be appended to the end.

Example: user_photos.save(pathToDirectory, name=NewName)


I used the following method to rename the uploaded file on the fly

file = request.files['file']file.filename = "abc.txt"  #some custom file name that you wantfile.save("Uploads/"+file.filename)