1

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 will be stored, and I am not really sure about this. Here is my code:

app.config['UPLOADS_DEFAULT_DEST'] = TOP_LEVEL_DIR + '/ppaysees/app/static/img/'

I got the following file structure

enter image description here

lfurini
  • 3,729
  • 4
  • 30
  • 48

1 Answers1

3

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
Hrabal
  • 2,403
  • 2
  • 20
  • 30