Handling File Uploads With Flask - miguelgrinberg.com

PHOTO EMBED

Tue Sep 06 2022 13:08:58 GMT+0000 (Coordinated Universal Time)

Saved by @Rmin #python #flask #uploadfile

    filename = uploaded_file.filename
    if filename != '':
        file_ext = os.path.splitext(filename)[1]
        if file_ext not in current_app.config['UPLOAD_EXTENSIONS']:
            abort(400)
content_copyCOPY

For every uploaded file, the application can make sure that the file extension is one of the allowed ones:

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