you can't get a "save as" dialog if the contents of the file are retrieved
via ajax (browsers don't work like that). Open a new window pointing to the
download url (it will soon close as there's no content to show, and the
"save as" dialog will pop up).
PS: you'd really want to use another system than the simple concatenation
to build the url... if "content" in your case contains csv data, you will
never be able to reach that url (because it won't be a valid url).
As last resort, at least urlencode the content. But you'll then face the
limitation of url size, and that's why usually those kind of things are
made with intermediate temp files or (slightly more complicated in a new
window) POST requests :P
On Monday, October 14, 2013 6:15:51 PM UTC+2, Kariloy Markief wrote:
>
> Hello,
>
> I'm writing an app that at some point has a text string dynamically
> generated in a view via javascript.
> What I would like to do is download that text as a file.
> For that purpose my attempted approach has been...:
>
> - on the same js function that generates the string I call:
>
> ajax('download_test?content='+content, [], '');
>
>
> and on the controller I have:
>
>
> def download_test():
>
> content = request.vars.content
>
> response.headers['Content-Type'] = 'text/csv'
> attachment = 'attachment;filename=data.csv'
> response.headers['Content-Disposition'] = attachment
>
> raise HTTP(200,str(content),
> **{'Content-Type':'text/csv',
> 'Content-Disposition':attachment + ';'})
>
>
> I've tried several variations around this approach, and the only thing
> that I can confirm is that the desired content is effectively passed from
> the the view to the controller (and back to the view if I define a
> container as the 3rd parameter of the ajax() function, but that's not what
> I want).
>
> So the problem here seems to be be triggering the download.
>
> I've tried this on firefox (running my app), and also on chromium (via
> minimal app just to reproduce this issue).
>
> I'm running web2py version 2.4.7
>
> Also the most similar reported issue I've found in this list was:
> https://groups.google.com/forum/#!topic/web2py/GH2HVCGPMKo
>
> Because no answer was found then and I was unsure about this group's
> policy of reviving old threads, I published mine as a new question. Hope
> this is ok.
>
>
>
>
>
>
>
>
>
>
--
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/groups/opt_out.