[mod_python] binary file, part II: name of file?

Deron Meranda deron.meranda at gmail.com
Wed Jun 7 20:16:47 EDT 2006


copying the list...

On 6/7/06, Webb Sprague <webb.sprague at gmail.com> wrote:
> > Perhaps the best way is to send a Content-Disposition header
> > (in addition to your Content-Type header).  You'll usually send
> > one of these two variants:
> >
> >   Content-Disposition: inline; filename=forecast-object-5.txt
> >   Content-Disposition: attachment; filename=forcast-object-5.txt
>
> Should I do this in mod_python by updating req.headers_out dict before
> calling req.write?  This is what I am going to try, just curious
> somebody's thoughts:
>
> req.headers['Content-Disposition'] = 'attachment; filename=forcast-object-5.txt'

Yes, that's what you do.  Be sure to set all your headers before
the first write.

Also, if you truly want to force a "save as", rather than perhaps an
"open or save"; you can also try to set the Content-Type header
to "application/octet-stream".  [Although your mileage may vary
with IE]
-- 
Deron Meranda


More information about the Mod_python mailing list