为什么常识

在GAE输出压缩文件并文件下载的方法(Pyt-on)

生活词典 changshi.cidiancn.com

阅读: 258

在GAE输出压缩文件并文件下载的方法(Pyt-on)现在我有一个文本数组,我要把每个元素单独保存为一个txt文件并压缩,在网页弹出下载。 有没有实现的可能? (Pyt-on语言)===============================已解决:如何在GAE 上动态生成zip 文件 - kjava - ITeye技术网站kjava.iteye/blog...1 个答案

答案 1:

可以的:s = StringIO.StringIO()z = zipfile.ZipFile(s, mode="w", compression=zipfile.Z-_DEFLATED)z.writestr("readme.txt","-ello world")z.close()self.response.-eaders["Content-Type"] = "application/x-zip"self.response.-eaders["Content-Disposition"] = "attac-ment; filename=test.zip"self.response.out.write(s.getvalue())

分享常识给亲友.