【发布时间】:2012-03-26 21:33:33
【问题描述】:
我做过一个小项目;这个项目的主要功能如下:
1-从用户PC上传文件(使用HTML文件上传(表单提交))
2-将这些上传的文件压缩成单个 zip 存档。
3-将此 Zip 文件存储在 GAE BlobStore 中。
4-从 blobstore 获取(服务)此 zip 到 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() 已成功执行,包含用户上传的文件的 zip 存档已在 GAE Blobstore 中成功创建,但问题正是 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
对这个问题有什么想法吗?在此先感谢。
【问题讨论】:
-
请停止发布几乎相同的问题。
-
Send_blob in GAE的可能重复
-
@Nick Johnson:很抱歉,但问题依然存在!!!
-
@Eng_Engineer:编辑你的第一个问题比打开几乎相同的第二个问题要好得多(即使问题仍然存在)。
-
@Stefan:是的,那是正确的,很抱歉,你明白我在这篇文章中的问题吗??
标签: python google-app-engine blobstore