1

I am making a mailing app in Python on the Google App Engine.

I want to enable an attachment upload (which posts to a BlobstoreUploadHandler) in a 'normal' webpage (posting to a RequestHandler).

If the user has filled part of the 'normal' form, how can I preserve those values after the user has uploaded his (or her) attachment (other then copying all the fields with javascript before submitting the post)?

  • Why don't you put all form controls in the same form that is going to be posted to the server? – Marc May 20 '13 at 19:09
  • @Marc The upload must be posted to a derived class of the BlobstoreUploadHandler and the rest of the form must be posted to a derived class of the RequestHandler. They therefor cannot be part of the same html
    .
    – rimvanvliet May 20 '13 at 19:18
  • the
    for the upload: `
    `, the
    for the rest: `
    `; upload_url is generated by GAE.
    – rimvanvliet May 20 '13 at 19:38

1 Answers1

2

You can write a request handler that derives from two classes:

class YourRequestHandler(BlobstoreUploadHandler, RequestHandler):
    pass

I also tried this with webapp2's RequestHandlers and it works.

P.S.: In order to prevent orphaned blobs because the user uploaded more files than your application expects (this can easily happen as you have no control over the user's browser), I suggest to write your post handler along the following lines:

def post(self):
    uploads = self.get_uploads()
    try:
        pass  # Put your application-specific code here.
        # As soon as you have stored a blob key in the database (using a transaction),
        # remove the corresponding upload from the uploads array.
    finally:
        keys = [upload.key() for upload in uploads]
        blobstore.delete_multi(keys)
Marc
  • 4,327
  • 4
  • 30
  • 46