python - Flask-Uploads always throwing 'UploadNotAllowed' error even with no constraints -


flask-uploads has called uploadset described "single collection of files". can use upload set save file predefined location. i've defined setup:

app = flask(__name__) app.config['uploads_default_dest'] = os.path.realpath('.') + '/uploads' app.config['uploaded_photos_allow'] = set(['png', 'jpg', 'jpeg']) app.config['max_content_length'] = 16 * 1024 * 1024  # setup flask-uploads photos = uploadset('photos') configure_uploads(app, photos)  @app.route('/doit', method=["post"]) def doit():     myfile = request.files['file']     photos.save(myfile, 'subfolder_test', 'filename_test')      return ''' blah ''' 

this should save ./uploads/photos/subfolder_test/filename_test.png

my test image is: 2.6mb , png file. when upload file, error:

... file "/home/btw/flask/app.py", line 57, in doit     photos.save(myfile, 'subfolder_test', 'filename_test') file "/usr/local/lib/python2.7/dist-packages/flaskext/uploads.py", line 388, in save     raise uploadnotallowed() uploadnotallowed 

however doesn't not allowed. have tried removing constraints, app still throws error. why?

edit:

okay, figured out it's not constraints causing problem. subfolder and/or filename causing problem:

# works # saves to: ./uploads/photos/filename_test.png photos.save(myfile) 

but want save custom location ./uploads/photos/<custom_subdir>/<custom_filename>. correct way of doing this?

you need give filename_test extension well

photos.save(myfile, 'subfolder_test', 'filename_test.png') 

the uploadset checks extension on new file name , throw exception if new extension not allowed.

since not giving new file extension, not recognize it.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -