jonathan topf
jonathan topf

Reputation: 8367

uploading files to blobstore whilst handling other fields

I have a form with a file input and a few text fields and i'd like to Upload the file to the blobstore and then handle the rest of the input. I have found documentation from google but I'm still fuzzy on the details. If I have the right idea you first generate a submit url for the form like so:

 blobstore.create_upload_url('/handlerURL')

where handlerURL is the url of the request handler that process the regular form data such as text fields etc

Next you define a BlobstoreUploadHandler, this is where i get fuzzy... From the documentation I understand that the BlobstoreUploadHandler deals with uploading the file then passes a rewritten request to \handlerURL. My confusion arrises when in the docs here:

https://developers.google.com/appengine/docs/python/tools/webapp/blobstorehandlers

an instance of a data model object is created inside the BlobstoreUploadHandler

but if i were to want to do additional processing and use data from other fields in the request handler at handlerURL then the BlobstoreUploadHandler would just be empty, is this correct or am i misunderstanding the process?

Upvotes: 1

Views: 266

Answers (2)

Slawek Rewaj
Slawek Rewaj

Reputation: 819

This is indeed a little tricky as two handlers are involved here.

  • The first one is from blobstore itself. Its URL is returned by the create_upload_url call. It's task is to save file (or files), and to replace it with blobkey. Then it just posts the form to your main handler.
  • The second one is defined by you. In your case its URL is /handlerURL. In most cases BlobstoreUploadHandler is used here, but it doesn't have to. BlobstoreUploadHandler makes it easier to retrieve blobkeys and that's all about it. Apart from that it's just a webapp.RequestHandler, so you can process your whole form here

Upvotes: 0

Stuart Langley
Stuart Langley

Reputation: 7054

BlobstoreUploadHandler just sanitizes the file upload part of the multipart message, you can still access the rest of the fields of your form using webapp the standard way (e.g. self.request.get('some_field_in_the _form')).

Upvotes: 2

Related Questions