flaskflask-uploadsflask-reuploaded

I am using flask_uploads and am getting this error ImportError: cannot import name 'patch_request_class' from 'flask_uploads'


my code looks like this

from flask_uploads import IMAGES, UploadSet, configure_uploads, patch_request_class
import os

basedir = os.path.abspath(os.path.dirname(__file__))
app.config['UPLOADED_PHOTOS_DEST'] = os.path.join(basedir, 'static/images')
photos = UploadSet("photos", IMAGES)

configure_uploads(app, photos)
patch_request_class(app)

what could be the issue. Can I get any help on how to resolve the problem


Solution

  • Very recently, patch_request_class was removed from Flask-Reuploaded, the maintained fork of Flask-Uploads, which gets installed as flask_uploads to stay compatible (and so you did not need to change imports).

    Are you sure you use Flask-Uploads and not Flask-Reuploaded? Have a look at your requirements.txt or setup.py.

    Here is the commit where patch_request_class gets removed.

    As you can read, patch_request_class was deprecated for a long time already, and it was only necessary to restrict uploads up to Flask version 0.6. Since then you can use the MAX_CONTENT_LENGTH environment variable of Flask itself, see https://flask.palletsprojects.com/en/1.1.x/config/#MAX_CONTENT_LENGTH

    tl/dr