0

I currently have a python-based GAE site that has a signup form where users can input account details along with a profile image to register. Based on suggestions from SO, I'm going with a mix of datastore and blobstore so it seems that this would require a simultaneous datastore put and a blobstore upload

However, from the google docs and the sample code I've been able to get running, it looks like the blobstore upload requires a redirect to a separate upload handler which conflicts with the datastore post handler (part of the current form handler)

Have been primarily referencing the following example for blobstore: https://cloud.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob

Wanted to see what is the best way to handle this type of setup? I assume this would be quite a common form of usage... any sample code would be very helpful!

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Dennis
  • 249
  • 1
  • 4
  • 17
  • 2
    Checkout this question http://stackoverflow.com/questions/17294507/google-app-engine-error-uploading-file-to-blobstore-from-python-code/17309002#17309002 but better try to use Cloud Storage. – Dmytro Sadovnychyi Oct 02 '14 at 12:54
  • As far as I understand your use case, user data and a reference to an image will be stored in Datastore. You will not have the reference before an image is stored, so upload handler is a way to go, but +1 Dmitry - use GCS. – Nikita Uchaev Oct 02 '14 at 13:06
  • Thanks, will look into GCS as well. Is it preferred because blobstore is expected to be phased out? – Dennis Oct 02 '14 at 13:34

1 Answers1

1

Yes, this is straightforward to do.

On your web page, you have a form that a user can use to submit a profile image. You can have other form elements in this form and post this other data as well (user name, etc.) as well as the image.

In your blobstore upload handler, you receive all of the form data -- the image and any other form elements that you have. The blobstore upload handler can call a put to add data to the datastore in addition to storing the file in the blobstore.

new name
  • 15,861
  • 19
  • 68
  • 114
  • Thanks, have gotten it to work with your solution. Actually found a good reference in the app engine docs for blobstore handlers: https://cloud.google.com/appengine/docs/python/tools/webapp/blobstorehandlers – Dennis Oct 02 '14 at 13:33