Skip to content Skip to sidebar Skip to footer

Flask Upload How To Configure File Storage Path

I'm building an app in Python Flask: I want users to be able to upload photos, and I am using the flask_upload extension. I want to set up the locations where the uploaded files wi

Solution 1:

If you plan to have one directory with all the files in it, you can use the UPLOADED_FILES_DEST variable.

UPLOADS_DEFAULT_DEST is used to work with Upload Sets (which I recommend) like so:

app.config['UPLOADS_DEFAULT_DEST'] = TOP_LEVEL_DIR + os.path.join('ppaysees', 'app', 'static', 'img')
photos = UploadSet('photos', uploads.IMAGES)

# then you can simply call the Upload Set api:
photos.save(request.files['photo'])  # Save a photo
photos.load(id)  # Load a photo
url = photos.url(photo.filename)  # get photo url

Post a Comment for "Flask Upload How To Configure File Storage Path"