我工作的小项目(即成)文件得到的Blob存储在GAE
2-将这些上传的文件压缩到单个zip压缩文件中。
将此Zip文件存储在GAE BlobStore中。
将此zip从blobstore获取(服务)到PC中(下载此zip以在本地获得)。
步骤1,2和3正确完成,但步骤4中的问题;我不能从blobstore下载此Zip; 这是我使用的代码:
from __future__ import with_statement
from google.appengine.api import files
import cgi, cgitb ; cgitb.enable()
import StringIO
import zipfile
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
glob_blob_info=""
class zip():
def z(self):
form = cgi.FieldStorage()
zipstream=StringIO.StringIO()
zfile = zipfile.ZipFile(file=zipstream,mode="w",compression=zipfile.ZIP_DEFLATED)
file_upload = form['file[]']
filename2 = file_upload.filename
data=file_upload.file.read()
zfile.writestr(filename2,data)
zfile.close()
zipstream.seek(0)
zip_file = files.blobstore.create(mime_type='application/zip',_blobinfo_uploaded_filename='test.zip')
with files.open(zip_file, 'a') as f:
f.write(zipstream.getvalue())
files.finalize(zip_file)
blob_key = files.blobstore.get_blob_key(zip_file)
print blob_key
blob_info = blobstore.BlobInfo.get(blob_key)
print blob_info
global glob_blob_info
glob_blob_info=blob_info
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
print "doaa"
global glob_blob_info
glob_blob_info = urllib.unquote(glob_blob_info)
blob_info = blobstore.BlobInfo.get(glob_blob_info)
self.send_blob(glob_blob_info,save_as=True)
def main():
application = webapp.WSGIApplication([('/serve', ServeHandler),], debug=True)
debug=True)
c=zip()
c.z()
run_wsgi_app(application)
if __name__ == "__main__":
main()
现在class zip()
执行successfuly使得含有由用户上载的文件zip存档在GAE Blob存储successfuly创建的,但问题正是该class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
没”牛逼执行 当我跑这个代码,我有这样的输出:
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
有任何想法,这个问题在此先感谢?
请停止发布几乎相同的问题。 – 2012-03-27 11:14:56
[SendEblob in GAE]的可能重复(http://stackoverflow.com/questions/9880865/send-blob-in-gae) – 2012-03-27 11:15:17
@Nick Johnson:对不起,但问题仍然存在! – 2012-03-27 16:21:11