I have a form that includes an element for loading an image between text fields.
I want to save blob in blobstore and reference it in my model ( ndb.Model) with ndb.BlobKeyProperty().
The method shown in this link uses the load handler ( UploadHandler), which is called from the link created in this way:
upload_url = blobstore.create_upload_url('/upload')
upload_url- This is the action of the form on the page created to download blob. However, my form includes other fields that are not processed in the post method UploadHandler. The workaround I found is to create a handler for my form that inherits from my BaseHandler and from BlobstoreUploadHandler:
class EditProfile(blobstore_handlers.BlobstoreUploadHandler, BaseHandler)
def get(self):
params['upload_url'] = blobstore.create_upload_url('/upload_blob1')
... fields ...
def post(self):
upload_blob = self.get_uploads()
blob_key = upload_blob[0].key()
value_field1 = self.request.POST.get('field1')
value_field2 = self.request.POST.get('field2')
value_field3 = self.request.POST.get('field3')
...
, , main.py , blob:
app = webapp2.WSGIApplication([ ('/upload_blob1', handlers.EditProfile),
('/upload_blob2', handlers.EditBlob2Handler),
('/serve/([^/]+)?', handlers.ServeHandler) ],
debug=os.environ['SERVER_SOFTWARE'].startswith('Dev'), config=webapp2_config)
. (: UploadHandler), ? , GAE, .