On Mon, Jan 5, 2009 at 3:11 PM, m h <[email protected]> wrote:
>
> On Mon, Jan 5, 2009 at 10:20 AM, mk <[email protected]> wrote:
>>
>> Hello everyone,
>>
>> I'm a beginner with Pylons and am trying to set the filename of a file
>> to download in an action (that is, controller method):
>>
>>     def environ3(self):
>>         msg = list(request.environ.items())
>>         msg = [ str(el[0]) + " " + str(el[1]) for el in msg ]
>>         msg.sort()
>>         msg = "<br>\n".join(msg)
>>         fname = r'C:\Documents and
>> Settings\Administrator\HelloWorld\helloworld\controllers\re.txt'
>>         fapp = fileapp.FileApp(fname, content_type="text/plain",
>> Content_Disposition="attachment; filename=re.txt")
>>         fapp.set_content(msg)
>>         retval = fapp(request.environ, self.start_response)
>>         return retval
>>
>>
>> A few questions:
>>
>> 1. why doesn't fapp.set_content method work? It silently quits, but the
>> actual file downloaded has contents of the file on the disk, not the
>> string I pass to the set_content method.
>>
>> Is there a way to pass the string to have it sent to the browser as
>> file? If I set response.content_type to e.g. "application/zip" and
>> return the string in the controller, the file with that content gets
>> sent, except it has wrong name. Is there a way to set it?
>>
>> 2. Is there a simpler way to send the desired file with desired name and
>> MIME type? To be frank, the above is a bit of rigmarole.
>>
>> thanks in advance,
>> Marcin
>>
>
>
> Here's what I'm using:
>
>
>        response.headers["content-type"] = "application/vnd.ms-excel"
>        response.headers["Content-Disposition"] = "attachment;
> filename=%s" % xls_filename
>
> cheers,

yes, in the future please read mailing list archives, this has been
asked at least twice in the past month.

--~--~---------~--~----~------------~-------~--~----~
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