Skip to content Skip to sidebar Skip to footer

Send_blob In Gae

i created zip files into the blobstore in GAE,then i tried to get(download)this zip file using this code: def send_blob(blob_key_or_info, content_type=None, save_as=None): CON

Solution 1:

You need to implement a Blobstore download handler to serve the file. For example:

from google.appengine.ext.webapp import blobstore_handlers

classServeZip(blobstore_handlers.BlobstoreDownloadHandler):
  defget(self):
    blob_key = self.request.get('key')
    ifnot blobstore.get(blob_key):
      logging.info('blobstore.get(%s) failed' % blob_key)
      self.error(404)
      return

    self.send_blob(blob_key)
    return

Then on the client you'd call: http://yourapp.appspot.com/servezip?key=<your_url_encoded_blob_key>

For the example above: http://yourapp.appspot.com/servezip?key=C25nn_O04JT0r8kwHeabDw%3D%3D

Solution 2:

Well Google provides very good api to process BlobStore objects, mainly Two Clsses named as BlobstoreDownloadHandler and BlobstoreUploadHandler.

To download content try to use BlobstoreDownloadHandler and the below code help you to understand the concept.

from google.appengine.ext.webapp import blobstore_handlers
    from google.appengine.ext.blobstore import BlobKey

    classVideoDownloadHelper(blobstore_handlers.BlobstoreDownloadHandler):
        defget(self, blobkey):
            blobKey = BlobKey(blobkey)
            #content_type is optional and by default it is same as uploaded content's content-type.
            self.send_blob(blobKey, content_type="image/jpeg")

And this method can be use like

    app = webapp2.WSGIApplication([(r'/download-video/([^\.]+)', VideoDownloadHandler)])

For further reading you can go through this https://cloud.google.com/appengine/docs/python/blobstore/

Post a Comment for "Send_blob In Gae"