Skip to content

Instantly share code, notes, and snippets.

@tanelpuhu
Created October 27, 2011 15:18
Show Gist options
  • Save tanelpuhu/1319851 to your computer and use it in GitHub Desktop.
Save tanelpuhu/1319851 to your computer and use it in GitHub Desktop.
kolm faili ühte... umbes nii?
self.response.headers['Content-Type'] = 'application/zip'
self.response.headers['Content-Disposition'] = 'attachment; filename="example.zip"'
self.response.headers['Content-Length'] = len(text)
self.response.headers['Content-Transfer-Encoding'] = 'binary'
self.response.out.write(text)
#!/usr/bin/env python
"zip"
from StringIO import StringIO
from zipfile import ZipFile
zio = StringIO()
zipper = ZipFile(zio, 'w')
zipper.writestr('file_1.txt', '1')
zipper.writestr('file_2.txt', '22')
zipper.writestr('file_3.txt', '333')
zipper.close()
fl = open('files.zip','wb')
fl.write(zio.getvalue())
fl.close()
zio.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment