I’ve had some problems with handling forms and getting back to basics after an upgrade I can’t get the minimal example to work:
class PhotoUploadFormHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % blobstore.create_upload_url('/upload_photo'))
self.response.out.write('''Upload File: <input type="file" name="file"><br> <input type="submit"
name="submit" value="Submit"> </form></body></html>''')
class PhotoUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
try:
upload = self.get_uploads()[0]
user_photo = UserPhoto(user=users.get_current_user(),
blob_key=upload.key())
db.put(user_photo)
self.redirect('/view_photo/%s' % upload.key())
except Exception, ex:
self.response.out.write(str(ex))
app = webapp2.WSGIApplication([
('/upload_form', PhotoUploadFormHandler),
('/upload_photo', PhotoUploadHandler),
The above return the exception at accessing the uploaded file:
list index out of range
Why?
Thanks for any help.
It seems that *get_uploads* is returning an empty list. Accordingly, the
[0]fails.