Suggesting a filename on a HTTP-request by sending someting in the header of the reply

Jeremy Lowery jslowery at
Fri Sep 20 02:24:14 EDT 2002

> I got a simple webserver serving files, but the files are found using
> lookup based on ids ( like http://localhost/dl?id=10, where 10 is a key in
> dictionary pointing to a file ), not their filename so when I send
> content-type = 'application/octet-stream' in the headers to the client I
> the proper "Save as ..."-dialog, but the filename is all screwed up. It
> to be the "dl"-part of the url above. I've tried to read the RFC
> 2616-document and sent "Content-Disposition"-headers etc. but with no
> What headers do I need to send for it to get the proper filename in the
> "Save as ..."-dialog? Say for instance that the filename I wanted the
> to save the file as was "".

The Content-Type (along with the file extension in Internet Explorer)
dictate what the browser
will do when it recieves the file. Internet Explorer also completely
ingnores content-types, and
it tries to guess what the content-type of the document is. Depending on the
MIME type
configuration of the client, it may
prompt to download, automatically open the file, etc. The easiest (and most
common way) to to
include this functionality is to put "right click and save target as" near
the link. the
Content-Disposition will give a source of the file (a filename; very useful
when using CGI to
dynamically send files), but it has nothing to do with the content-type and
how the browser
reaacts to it.

Content-Disposition: file; filename=%(filename)s

is the proper way to use the http header to show the "filename" of what is
being downloaded.

J Lowery

More information about the Python-list mailing list