filename = "%s-backup" % (time.strftime("%Y%m%d-%H%M"))
raw_data = <a bunch of data>
stream = cStringIO.StringIO()
zip_file = zipfile.ZipFile(stream, "w", zipfile.ZIP_DEFLATED, False)
zip_file.writestr(filename, raw_data)
response.headers['Content-Type'] = "application/octet-stream"
response.headers['Content-Disposition'] = "attachment;
filename=%s%s.bin" % (time.strftime("%Y%m%d-%H%M"), filename)
return response.stream(stream, request=request)
Thanks,
Matt
I would prefer not to touch the disk if possible, these are not huge
files just logs. I think I'm very close, when I serve this without the
zipfile code (just wrapping raw_data in a StringIO), a dialog pops up
asking me to save the file. However, with the zipfile code, the
request seems to take much longer (as if its downloading something)
and then an error is displayed in the dev console:
"Failed to load resource"
"Unsafe JavaScript attempt to access frame with URL
chrome://chromewebdata/ from frame with URL http://10.0.15.97:2345/.
Domains, protocols and ports must match."
Perhaps the headers need to be modified to serve the zip file? Any
suggestions are welcome here!
Matt
Does this actually work for you? When I use this code, I get a
download, but it saves out a zero byte file with the proper name.
Matt