Hi Niphlod - I modified my response.stream call to include the filename argument. When I call the controller, the file does get downloaded. However, when ajax calls the controller, the file isn't downloaded.
@Leonel, a simple link, like A('download tar file', _href='%?attachment' % path_to_download_file) won't work because the file to be downloaded doesn't exist at the time the link is created. It needs to be generated on the fly. On Thursday, October 18, 2012 4:46:33 PM UTC+8, Niphlod wrote: > > the first thing is: when you navigate to mycontroller/mydownload (no ajax) > can you get the file downloaded ? > second thing missing from your code: if you want the content downloaded as > an attachment, set the content-disposition header to attachment; > filename=afilename.tar (or if you're using recent web2py version > response.stream(file, attachment=True, filename=afilename.tar)) > > On Thursday, October 18, 2012 8:09:09 AM UTC+2, weheh wrote: >> >> Is it possible to do a response.stream in the middle of an ajax callback? >> >> I want to give users a button, which if pressed, will tar up all their >> files and initiate a download. Something like this: >> >> TAG.BUTTON(..., _onclick="ajax("%s", [], ':eval');" % >> URL(c='mycontroller', f='mydownload')) >> >> Then later, in mycontroller.py, >> >> def mydownload(): >> ... create tarfile ... >> return response.stream(tarfile, attachment=True) >> >> I tried it, but (perhaps obviously to some) it doesn't work. So, how to >> get the mydownload() action to cause the browser to download the tarfile? >> > --