开发者

How to create a download link to access an object inside the Google memcache

开发者 https://www.devze.com 2023-01-28 20:00 出处:网络
I have an application running inside the Google App Engine开发者_高级运维. This application creates entrys inside the memcache and I want to access each entry as a file via a download link. Is this po

I have an application running inside the Google App Engine开发者_高级运维. This application creates entrys inside the memcache and I want to access each entry as a file via a download link. Is this possible?


You need to define your own handler, which takes the key as part of the URL, or a query string, and returns the appropriate object from memcache.

Remember that memcache is intended to be a cache, not a reliable storage mechanism, so you should have some way to retrieve an object even if it's been evicted from the cache.


I use this to handle swf-files stored in as blobs. You should easily be able to modify it to suit your needs and type of files.

class SwfHandler(webapp.RequestHandler):
def get(self):
    query = cgi.FieldStorage()
    swf = BlobStorage.get_by_id(int(query.getvalue('id')))

    if swf:
        self.response.headers['Content-Type'] = 'application/x-shockwave-flash'
        self.response.out.write(swf.fileData)
    else:
        self.error(404)   

## add "('/swfhandler/', SwfHandler)" to your application :
application = webapp.WSGIApplication([('/swfhandler/', SwfHandler), ****)

I request the file with: /swfhandler/?id=12


Unless I'm missing something, it should be as simple as outputting appropriate headers before outputting the entry contents you fetched.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号