Pushing file name to browser

Hakan Nilsson hakan at netg.se
Sun Mar 7 04:48:47 CET 2004


On Sat, 6 Mar 2004, pxlpluker wrote:

> I what to dynamically create a page that has download links to file
> stored on disk.
>
> the part i don't know how to do (or if its possible) is to a different
> name appear in the browser DL window.
>
> i.e. I want the files stored with a random string but when being DL to
> have real name show in File Save dialog.
>
> in essence i want to push the file name to the browser
>
> Fred

This is not so much a python issue as it is an issue of knowing what the
browsers do when they get special input.
But, since I recently did this myself I have the answer handy. ;o)

Most browsers check the name between the last / and the end of the line
(or "?" if you have extra get-parameters) and put that as default name in
the file save-dialog. So all you need to do is something like the following:

info = { "filename": "apa.txt", "fileid": "10001" }
the_url = '<a href="download.py/%(filename)s?id=%(fileid)s">%(filename)s</a>'%info

As far as I can tell you are only interested in the file id, then this
should work with no problem for you and you can get the id-parameter
through the standard cgi-object, or however you chose to do.
The filename (essentially anything you chose to put between the / and the ?)
will be available through an extra-path-info variable, probably also
available in the standard cgi-object.

Hope this helps,

/Hakan

-
 Hi! I'm a .signature virus!
 Copy me into your .signature file to help me spread!





More information about the Python-list mailing list