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, **{"content_type":"text/plain",

"Content-Disposition":"attachment; filename="+filename})
        return fapp(request.environ, self.start_response)

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