6

Download the zip archive from blobstore in Google AppEngine

 3 years ago
source link: https://www.codesd.com/item/download-the-zip-archive-from-blobstore-in-google-appengine.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Download the zip archive from blobstore in Google AppEngine

advertisements

I worked on Google app engine with python. I created zip archives into tho blobstore, but there is a problem when I try to download this file.

I will show some details: first, I created this archive on the blob and then I got the key of this uploaded file. I want to send this key in url to another python page like this:

print'<a href="download.py?key=%s">Save Zip</a>' % blob_key

Now in download.py page, I tried to get the key from the url as: self.request.get('key'), but it doesn't work.

In this page I wrote

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):

......etc

This is the only class I used to download the zip, but the problem is I can't get the key, and when I run the application, I get this problem:

****Status: 404 Not Found
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0****

app.yaml code:

application: cloudcomputingproject20122012
version: 1
runtime: python
api_version: 1

handlers:
- url: /compress.py
  script: compress.py
- url: /decompress.py
  script: decompress.py
- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html

Now in compress.py i made two classes;creating zip,storing it on blobstore,getting the bob key for this stored file then i defined blob key as global variable ,now in serve handler class i try to download this zip,but i can't.

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self):

    global x
    #x="tvsD0KgYxX85hyC9wJHsqw=="
    print x
    x = str(urllib.unquote(x))
    blob_info = blobstore.BlobInfo.get(x)
    self.send_blob(blob_info,save_as=True)

def main():
    application = webapp.WSGIApplication( [('/serve', ServeHandler),], debug=True)
    c=zip()
    c.z()
    run_wsgi_app(application)

if __name__ == "__main__":
    main()


Python on App Engine is not like PHP - request URLs do not map directly to filenames; you can't point to /download.php and expect requests to be routed to your handler. You need to map your handler to a URL, then point requests at that URL; see any of the Getting Started tutorials for examples.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK