1

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

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
Victor02
  • 15
  • 5

1 Answers1

4

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

  • remove the patch_request_class import
  • remove patch_request_class(app)
  • set MAX_CONTENT_LENGTH to desired value
Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
  • 2
    Hi Eric, as I wrote in my answer, `patch_request_class` is a ancient function, and it was only needed for Flask version 0.6 - Flask 2.0 will be released shortly. Also, `Flask-Uploads` has not seen a new release in many years. `Flask-Reuploaded` is the way to go, as it is actively maintained, and even a security risk in `Flask-Uploads` was fixed in `Flask-Reuploaded`. As I described above, the way forward is to remove `patch_request_class` from your code and to use `Flask-Reuploaded`. – Jürgen Gmach May 06 '21 at 06:12
  • If you use an application you don't develop, you may need this deprecated function. To use previous version, you can use `pip install git+https://github.com/jugmac00/flask-reuploaded@53234dd` which will install the library just before it was removed. – abonne01 Nov 21 '22 at 23:49