On May 17, 2007, at 4:09 PM, m h wrote:
>
> On 5/17/07, m h <[EMAIL PROTECTED]> wrote:
>> Hey all-
>>
>> I've got a controller method for downloading files. It appears to
>> work ok, but I'd like to make it so the browser names the file as the
>> file name rather than the method name.
>>
>> Here's the method:
>>
>> def get(self):
>> filename = os.path.join(self.csv_dir, request.params.get
>> ("filename"))
>> fapp = fileapp.FileApp(filename, **{"content_type":"text/
>> plain",
>>
>> "content_location":"foo.txt"})
>> return fapp(request.environ, self.start_response)
>>
>> So when I access this method the browser defaults to naming the file
>> "get". Is there a way to set an HTTP header to set the filename? Or
>> should I resort to routes mapping and pass the name of the file in
>> the
>> url rather than as a request parameter? Perhaps there's another way?
>>
>
> I'll answer myself
>
> Here's how to do it with headers (use "Content-Disposition" header)...
>
> def get(self):
> filename = os.path.join(self.csv_dir, request.params.get
> ("filename"))
fapp = fileapp.FileApp(filename)
fapp.content_disposition(filename='foo.txt')
# should also work
> return fapp(request.environ, self.start_response)
Also I'll point out that FileApp uses the mimetypes module to guess
the content-type. In this case it would have guessed 'text/plain' for
'foo.txt'.
--
Philip Jenvey
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---