Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Pushing file name to browser

Reply
Thread Tools

Re: Pushing file name to browser

 
 
Hakan Nilsson
Guest
Posts: n/a
 
      03-07-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!


 
Reply With Quote
 
 
 
 
A.M. Kuchling
Guest
Posts: n/a
 
      03-07-2004
On Sun, 7 Mar 2004 04:48:47 +0100 (CET),
> info = { "filename": "apa.txt", "fileid": "10001" }
> the_url = '<a href="download.py/%(filename)s?id=%(fileid)s">%(filename)s</a>'%info


Another approach is to include a Content-Disposition header in the
response that suggests a filename, something like this:

Content-Disposition: inline; filename="paid-for-download.zip"

Most browsers will then suggest paid-for-download.zip as the filename, no
matter what form the download URL takes. See RFC2183 for the details of
this header.

--amk

 
Reply With Quote
 
 
 
 
Irmen de Jong
Guest
Posts: n/a
 
      03-07-2004
A.M. Kuchling wrote:
> Content-Disposition: inline; filename="paid-for-download.zip"

^^^^^^
shouldn't that read attachment ?

--Irmen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pushing multiple xml through a xsl file to generate a single htmlpage graham.reeds XML 9 02-04-2008 08:59 AM
Pushing a file to the user.. =?Utf-8?B?UmF2aSBK?= ASP .Net 4 03-03-2005 03:43 PM
Pushing file name to browser pxlpluker Python 1 03-06-2004 04:56 PM
Pushing file name to browser pxlpluker Python 0 03-05-2004 02:44 PM
Using response.addheader for pushing file Bertrand ASP General 0 11-11-2003 08:17 AM



Advertisments