简体   繁体   中英

Download zip archive from blobstore in Google AppEngine

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.

Did you look at the example here ? It seems you're doing exactly the same thing.

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, resource):
    resource = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)

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