I am trying to implement Flask-Uploads in my project. However, I am having trouble because I am using an application factory function and cannot access the UploadSets from other files in the app!
FILE: app/__init__.py
from flask_uploads import UploadSet, configure_uploads, IMAGES
def create_app(object_name):
...
images = UploadSet('images', IMAGES)
configure_uploads(app, images)
FILE: app/controllers/editions.py
from flask_uploads import UploadNotAllowed
# this is one of my route files, registered in a blueprint
editions = Blueprint('editions', __name__)
...
# inside one of the routes
poster = request.files.get('poster')
try:
filename = images.save(poster)
except UploadNotAllowed:
flash('The upload was not allowed.', category='warning')
else:
# add to db...
Of course this won't work because images
is not defined. But how to I import it from the app?
I tried:
import app
app.images.save(...)
from flask import current_app
current_app.images.save(...)
from app import images
None works. Any ideas???
PS: everything else in my app is working fine except this.