简体   繁体   中英

Simultaneous Google Datastore and Blobstore Upload With Google App Engine (Python)

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM