You can use the CherryPy server with Pylons, which I assume is what
Sandeep is doing. But I don't understand why he's using the CherryPy
header API, and I'd be surprised if it even works in a Pylons
controller.

Here's how I force a text file to be downloaded rather than displayed
in Pylons 1:

            response.content_type = "text/plain"
            response.charset = "utf-8"
            response.headers["Content-disposition"] = (
                             "attachment; filename=MyChemicals.txt")

In Pyramid you'd set the corresponding ``self.request.response_*``
attributes (only a few of these are defined, they may not cover all
these headers).  Or create a Response object, set them on it, set the
body to the file content, and return the response.

On Thu, Feb 24, 2011 at 6:46 AM, Jonathan Vanasco <[email protected]> wrote:
> you should ask on the cherrypy list.  that is another webserver,
> different than pylons.
>
> On Feb 24, 3:48 am, Sandeep Kulkarni <[email protected]>
> wrote:
>> Hi,
>>
>> Following is my back end code in python.
>>
>>     def download_key(self):
>>         import cherrypy
>>         cherrypy.response.headers['Content-Type'] =
>> "application/octet-stream"
>>         cherrypy.response.headers['Content-Disposition'] = 'attachment;
>> filename="myfile.pem"'
>>         return "These are file content"
>>
>> And the front end code is as follows in extjs.
>>
>> function downloadFile(){
>>     var url='/download_key';
>>
>>     var ajaxReq=ajaxRequest(url,0,"GET",true);
>>     ajaxReq.request({
>>         success: function(xhr) {
>>             Ext.MessageBox.alert(_("Success"), xhr.responseText);
>>         },
>>         failure: function(xhr){
>>             Ext.MessageBox.alert( _("Failure") , xhr.statusText);
>>         }
>>     });
>>
>> }
>>
>> I am getting response at front end in a message box. But I need that
>> response text in a file.
>> Please help me if you know the solution.
>>
>> Regards,
>> Sandeep
>>
>>
>>
>> On Tue, 2011-02-22 at 23:30 +0530, Eric Rasmussen wrote:
>> > I am not familiar with extjs, but in your example it appears that the
>> > success scenario is commented out. Also, should the "response"
>> > variable be "xhr.response"? "response" will evaluate to undefined in
>> > the function as you pasted it (unless it's a magic variable that is
>> > part of extjs?), and if it's a global variable declared elsewhere,
>> > it's probably not the response text from the AJAX call.
>>
>> > Otherwise it would definitely help to see the server-side code you're
>> > using for the file content.
>>
>> > Best,
>> > Eric
>>
>> > On Tue, Feb 22, 2011 at 2:40 AM, Sandeep Kulkarni
>> > <[email protected]> wrote:
>>
>> >         Hi,
>>
>> >         Thanks but I have already tried this solution. I didn't get
>> >         file downloaded on client machine.
>>
>> >         I have following code at client side. Is any thing lacking
>> >         there? I am using AJAX here in extjs.
>>
>> >         function downloadFile(){
>> >             var url='/download_key';
>>
>> >             var ajaxReq=ajaxRequest(url,0,"GET",true);
>> >             ajaxReq.request({
>> >                 success: function(xhr) {
>> >                     //Ext.MessageBox.alert(_("Success"), response);
>> >                 },
>> >                 failure: function(xhr){
>> >                     Ext.MessageBox.alert( _("Failure") ,
>> >         xhr.statusText);
>> >                 }
>> >             });
>> >         }
>>
>> >         Regards,
>> >         Sandeep
>>
>> >         On Tue, 2011-02-22 at 13:28 +0530, Graham Higgins wrote:
>>
>> >         > -----BEGIN PGP SIGNED MESSAGE-----
>> >         > Hash: SHA1
>>
>> >         > Hi,
>>
>> >         > On 22 Feb 2011, at 07:01, Sandeep wrote:
>>
>> >         > > I have some text content in database field. I want to download 
>> > that
>> >         > > text content from database field on client machine.
>>
>> >         
>> > >http://stackoverflow.com/questions/790019/how-do-i-return-a-csv-from-...
>>
>> >         > shows how to do this for a .csv file.
>>
>> >         > > I want this text content in a file at client side.
>>
>> >         > This isn't really related to Pylons, you just need to set the 
>> > relevant
>> >         > HTTP response headers:
>>
>> >         >http://www.webmasterworld.com/forum88/12908.htm
>>
>> >         > - --
>> >         > Cheers,
>>
>> >         > Graham
>>
>> >         >http://bel-epa.com/gjh/
>>
>> >         > -----BEGIN PGP SIGNATURE-----
>>
>> >         > iEYEARECAAYFAk1jbJAACgkQOsmLt1Nhivzv/gCfUEtz6r6GeIb+kM+5s9XsUx9E
>> >         > 1nAAoNhiV5LKetd8RaUMd9mQZOxQExe3iQCVAgUBTWNskFnrWVZ7aXD1AQJcYQP9
>> >         > Ebu6uZNyQVpw9ZBB1M3i3laoaYrIN6vecg0DLV9h77Nzx+oGbQ/VntEG2If33j91
>> >         > jBgTScRn8ZTvfKagQUKW/kqjVNc3w9Kqo3e+iSPaV/zE3PmUPfSxJ9nhkTOgqbNH
>> >         > z18t54X8PeViAfMgvnhg9ntzWYGohW9tdNyHt/IxJ1U=
>> >         > =+FQx
>> >         > -----END PGP SIGNATURE-----
>>
>> >         > --
>> >         > You received this message because you are subscribed to the 
>> > Google Groups "pylons-discuss" group.
>> >         > To post to this group, send email to 
>> > [email protected].
>> >         > To unsubscribe from this group, send email to 
>> > [email protected].
>> >         > For more options, visit this group 
>> > athttp://groups.google.com/group/pylons-discuss?hl=en.
>>
>> >         --
>> >         You received this message because you are subscribed to the
>> >         Google Groups "pylons-discuss" group.
>> >         To post to this group, send email to
>> >         [email protected].
>> >         To unsubscribe from this group, send email to pylons-discuss
>> >         [email protected].
>> >         For more options, visit this group at
>> >        http://groups.google.com/group/pylons-discuss?hl=en.
>>
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "pylons-discuss" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to pylons-discuss
>> > [email protected].
>> > For more options, visit this group at
>> >http://groups.google.com/group/pylons-discuss?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>



-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to