Hello,
I am trying to handle errors when uploading a file with a disallowed filetype or when submiting without selecting any file.
All I get is "flask_uploads.exceptions.UploadNotAllowed" and on the web page "Internal Server Error". I want to flash an error message but have no idea how to handle the error. I googled and I read the documentation but I couldn't find a way.
Everything works fine when selecting and submiting the right type of file/files(in this case IMAGES).
Thank you!
if request.method == 'POST':
if form.validate_on_submit() and 'artwork' in request.files:
art = form.artwork.data
this_artf = art_f+'/'+str(order_no_art)
app.config['UPLOADED_IMAGES_DEST'] = this_artf
images = UploadSet('images', IMAGES)
configure_uploads(app, images)
for image in art:
images.save(image)
As you said, you have looked in the documentation...
I just enhanced the example shown at https://github.com/jugmac00/flask-reuploaded with handling the mentioned
UploadNotAllowed
exception.Be sure to not forget to import the exception first!
This is a generic answer, but I am positive you can apply it to your case.
By the way, I saw you configured the app within the request handling:
While this currently works, this is not the way it is supposed to do.
It is about these lines...
You have to move those lines outside the request context, e.g. at the top of your module or in your application factory.
Disclaimer: I am the maintainer of
Flask-Reuploaded
.