Flask: What are the exceptions for werkzeug.datastructures.FileStorage.save()?

Viewed 548

When handling file uploads:

file = request.files['file']
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

what are the exceptions I should catch? The FileStorage documentation does not say anything about exceptions.

Reference: Flask file upload

1 Answers

Seems like some good logic in the Flask file upload link you've shared to protect against errors. Werkzeug does not throw any "special" exceptions with this operation, but as you can see in the source code they use the shutil python module and are catching errors on the file operations for you...

Not sure if this helps or if you're expecting other exceptions here. My approach here would be to test whether the operation was successful after you call save().

Related