I understand. The problem is that response.stream does not form for a StringIO which is not a regular file. StringIO is in memory therefore you have no reason for streaming.
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 stream.getvalue() ### << I only changed this On Oct 14, 1:13 pm, Matt Broadstone <mbroa...@gmail.com> wrote: > On Fri, Oct 14, 2011 at 12:48 PM, Massimo Di > Pierro<massimo.dipie...@gmail.com> wrote: > > What browser? > > That was chrome. The previously fix suggested by Brian works for me (thanks!). > > Matt > > > > > > > > > > > On Oct 14, 10:30 am, Matt Broadstone <mbroa...@gmail.com> wrote: > >> On Fri, Oct 14, 2011 at 9:35 AM, peter <peterchutchin...@gmail.com> wrote: > >> > If I now do exactly what I did one month ago, there is now no error > >> > with zip streaming. So maybe you have changed things in > >> > response.stream since then. > > >> > Peter > > >> > On Oct 14, 1:24 pm, peter <peterchutchin...@gmail.com> wrote: > >> >> I sent from my wifes > >> >> emailhttp://groups.google.com/group/web2py/browse_thread/thread/fe85dca9e4... > > >> >> However with hindsight I think I did not give sufficient information > >> >> in my forum entry. I guess I was seeing if other people had had > >> >> problems with downloading zip files. > > >> >> Today, I just tried the following > > >> >> def downloady(): > > >> >> import os > >> >> import contenttype as c > >> >> path="somepath/album.zip" > >> >> response.headers['Content-Type'] = c.contenttype(path) > >> >> response.headers['Content-Disposition'] = 'attachment; > >> >> filename=album.zip'# to force download as attachment > > >> >> return response.stream(open(path,'rb'),chunk_size=4096) > > >> 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. > > >> >> and this did work correctly. So I do not know why I was having > >> >> problems last month, when I repeatedly had problems with downloaded > >> >> zip files not unzipping. > > >> >> So I aplogise for suggesting there was a bug here. I will see if I can > >> >> recreate the problems I was having and get to the root cause. > > >> >> Peter > > >> >> On Oct 14, 12:22 am, Massimo Di Pierro <massimo.dipie...@gmail.com> > >> >> wrote: > > >> >> > On Oct 13, 12:46 pm, peter <peterchutchin...@gmail.com> wrote: > > >> >> > > As I have reported previously in this forum, I think that > >> >> > > response.stream does not quite stream zip files correctly. > > >> >> > I have no bug report about this. Can you tell us more so we can fix > >> >> > it?- Hide quoted text - > > >> >> - Show quoted text -