从 appengine 数据存储区压缩一组 blob
我需要压缩数据存储中可用的一组 blob。 这些可以是不同类型的,例如一些 html/images/swf/ 等。 其中所有这些都可以作为 blob 在数据存储中使用。
我尝试实施这个解决方案: 在 App Engine (Python) 中压缩动态文件?
尝试使用一些静态文本效果很好,我还可以使用一组具有各自内容的文件创建一个 zip,但在从查询生成 zip 时我无法找出一些问题。
z.writestr(fil.Template_name, my_data.encode('UTF-8'))
File "C:\Python25\lib\zipfile.py", line 626, in writestr
self.fp.write(zinfo.FileHeader())
File "C:\Python25\lib\zipfile.py", line 260, in FileHeader
return header + self.filename + extra
UnicodeDecodeError: 'ascii' codec can't decode byte 0xde in position 12: ordinal not in range(128)
这是这部分代码的错误
class filesDB(db.model)
Template_file = db.BlobProperty()
Template_name= db.StringProperty()
output = StringIO.StringIO()
z = zipfile.ZipFile(output,'w')
files = filesDB.all().filter("fCreatedBy","sandeep")
for fil in files:
my_data = fil.Template_file
z.writestr(fil.Template_name, my_data)
z.close()
I need to zip a set of blobs available in data store.
These can of different types like some html/images/swf/ etc.
where all these are available in datastore as blob.
I tried to implement this solution:
Zipping dynamic files in App Engine (Python)?
Tried with some static texts it worked great, I am also able to create a zip with a set of files with respective content but I could not trace out some issue when making zip from query.
z.writestr(fil.Template_name, my_data.encode('UTF-8'))
File "C:\Python25\lib\zipfile.py", line 626, in writestr
self.fp.write(zinfo.FileHeader())
File "C:\Python25\lib\zipfile.py", line 260, in FileHeader
return header + self.filename + extra
UnicodeDecodeError: 'ascii' codec can't decode byte 0xde in position 12: ordinal not in range(128)
This is the error for this part of code
class filesDB(db.model)
Template_file = db.BlobProperty()
Template_name= db.StringProperty()
output = StringIO.StringIO()
z = zipfile.ZipFile(output,'w')
files = filesDB.all().filter("fCreatedBy","sandeep")
for fil in files:
my_data = fil.Template_file
z.writestr(fil.Template_name, my_data)
z.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 zipfile 文档:
尝试将文件名编码为 UTF-8,例如:
Per the zipfile documentation:
Try to encode your filename in UTF-8 for example with: