[mod_python] req.sendfile(): specifying a name for the file sent?

Adrian Holovaty modpython at holovaty.com
Mon May 9 19:18:42 EDT 2005


Calvin Chen wrote:
> Right now, when I use req.sendfile(), the file download prompt comes
> up and asks me if I want to download a file. So far so good. The
> contents of this file is exactly how I wanted it to be. So far so
> good.

You'll want to send out the "Content-Disposition" header. Set its value to 
this:

"attachment; filename=name.txt"

...where "name.txt" is whatever you want the filename to be.

In your example, the code would be:

def index(req):
    req.content_type='text/file'
    req.headers_out['Content-Disposition'] = 'attachment; filename=name.txt'
    req.sendfile('PATH_TO_FILE/name.txt')

Hope this helps!

Adrian

--
http://www.holovaty.com/


More information about the Mod_python mailing list