python - Upload with Flask-Uploads and Flask-WTF failing validation -


i cannot seem figure out why 1 field fails other succeeds in uploading file. can upload photo fine... when comes pdf, cannot pass validation. i've scoured code amiss can't find anything. funny thing able upload photo via manual upload set, doesn't make sense me. i'm guessing off how i've configured flask-wtf flask-uploads, seeing there's no documentation online on how use 2 together, had best.

any appreciated, need upload pdfs , has me stumped.

code below... ton!

config.py

uploaded_manuals_dest = "c:/pyprojects/cc/uploads/eq_manuals/" uploaded_manuals_allow = 'pdf' uploaded_photos_dest = "c:/pyprojects/cc/uploads/eq_photos/" uploaded_photos_allow = 'png, jpg, jpeg' 

__init__.py

from flaskext.uploads import uploadset, configure_uploads, patch_request_class photos = uploadset('photos') manuals = uploadset('manuals') configure_uploads(app, (photos, manuals)) patch_request_class(app) 

forms.py

class eqform(form):     name = stringfield('name', validators=[required('equipment name required.')])     photo = filefield('equipment photo', validators=[         fileallowed(photos, 'photo must png, jpg, or jpeg!')])     manual = filefield('equipment manual', validators=[         fileallowed(manuals, 'manual must pdf!')]) 

views.py

@app.route('/admin/equipment/', methods=['get', 'post']) @roles_accepted('admin') def equipment():      eqform = eqform()      if eqform.validate_on_submit():         # os.path.join() secured filename , root path config.py imported join()         new_eq = equipment(name = eqform.name.data)          if eqform.photo.data:             photo_path = join(                 app.config['uploaded_photos_dest'],                 secure_filename(eqform.photo.data.filename)                 )              eqform.photo.data.save(photo_path)             new_eq.photo_path = photo_path          if eqform.manual.data:             manual_path = join(                 app.config['uploaded_manuals_dest'],                 secure_filename(eqform.manual.data.filename)                 )              eqform.manual.data.save(manual_path)             new_eq.manual_path = manual_path          db.session.add(new_eq)         db.session.commit()      equipment = equipment.query.all()      return render_template('equipment.html',         title="equipment database",         equipment = equipment,         eqform = eqform         ) 

equipment.html

        <form action="" method="post" enctype="multipart/form-data" class="eq-field hide" name="eqform">       {{ eqform.hidden_tag() }}           <ul class="list-group">             <li class="list-group-item">               {{ eqform.name.label }}: {{ eqform.name }}             </li>             <li class="list-group-item">               {{ eqform.photo.label }}: {{ eqform.photo }} <br>               <span style="font-size:.75em;">photo must png, jpg, or jpeg.</span>             </li>             <li class="list-group-item">               {{ eqform.manual.label }}: {{ eqform.manual }} <br>               <span style="font-size:.75em;">manual must pdf.</span>             </li>           </ul>           <input type="submit" class="btn btn-default" value="submit">         </form> 

a silly stupid mistake me:

uploaded_manuals_allow = 'pdf' uploaded_photos_allow = 'png, jpg, jpeg' 

these 2 lists of allowed extensions had declared strings... changed them to:

uploaded_manuals_allow = ('pdf') uploaded_photos_allow = ('png', 'jpg', 'jpeg') 

however, interesting note: list still did not work single item, had add two:

uploaded_manuals_allow = ('pdf', 'pdf')


Comments