如何在 App Engine 中从 Google Storage 读取 zip 文件?
应用程序创建一个 zip 文件并将其存储到 Google Storage。我正在 Web 服务器端工作,负责抓取 zip 文件、提取内容等。Web 服务是用 Python App Engine 编写的。到目前为止,我已经设置了凭据,并且通过遵循教程,我可以列出存储桶内容。尽管我能够读取元数据和文件信息,但我无法将内容获取到 zip 文件模块。遵循此 我最终陷入了无法正常工作的位置:
uri = boto.storage_uri(BUCKET_NAME, GOOGLE_STORAGE)
objs = uri.get_bucket()
files = []
for obj in objs:
object_contents = StringIO.StringIO()
if obj.get_key():
obj.get_file(object_contents)
my_zip = zipfile.ZipFile(object_contents)
object_contents.close()
files.append(my_zip)
print len(files)
我收到: BadZipfile: 文件不是 zip 文件
如何正确读取内容?
An application creates a zip file and stores it to Google Storage. I am working on the web server side which is responsible for grabbing the zip file extract the contents etc. The web service is written in Python App Engine. So far I have set the credentials and by following the tutorials I am able to list buckets contents. Although I am able to read the metadata and file information I am not able to get the contents to zip file module. Following this
guide I have ended up in that spot which is not working:
uri = boto.storage_uri(BUCKET_NAME, GOOGLE_STORAGE)
objs = uri.get_bucket()
files = []
for obj in objs:
object_contents = StringIO.StringIO()
if obj.get_key():
obj.get_file(object_contents)
my_zip = zipfile.ZipFile(object_contents)
object_contents.close()
files.append(my_zip)
print len(files)
I am getting: BadZipfile: File is not a zip file
How can I read the content properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在有了API,您可以直接操作 Google Storage 中的对象。使用它,您可以获得 zipfile 的类似文件的对象,并将其传递给 zipfile 模块。
There's now an API that lets you manipulate objects in Google Storage directly. Using that, you can get a file-like object for the zipfile, and simply pass that to the
zipfile
module.