Hi!
I'm trying https://github.com/allanlei/python-zipstream.
As I understand, the only way to return the generator from web2py is:
raise HTTP(200, generator(), **headers)
*Is there a more correct way?*
Working example:
def download_zipstream():
import zipstream
import os
p = 'path/to/files'
z = zipstream.ZipFile()
for fname in os.listdir(p):
fp = os.path.join(p,fname)
z.write(fp, fname) # - in fact, it's just collecting filenames (no
actual reading/zipping/writing)
headers = {}
headers['Content-Type'] = 'application/zip'
headers['Content-Disposition'] = 'attachment; filename="files.zip"'
def zstream():
for prt in z: # - all magic here
yield prt
raise HTTP(200, zstream(), **headers)
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.