Handling File Uploads With Flask - miguelgrinberg.com

PHOTO EMBED

Tue Sep 06 2022 14:20:40 GMT+0000 (Coordinated Universal Time)

Saved by @Rmin #python #validation #flask #uploadfile

        if file_ext not in app.config['UPLOAD_EXTENSIONS'] or \
                file_ext != validate_image(uploaded_file.stream):
            return "Invalid image", 400
content_copyCOPY

The second error condition is generated by the application when any of the validation checks fails. In this case the error was generated with a abort(400) call. Instead of that the response can be generated directly:

https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask