Re: Pushing file name to browser

Discussion in 'Python' started by Hakan Nilsson, Mar 7, 2004.

  1. 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!
    Hakan Nilsson, Mar 7, 2004
    #1
    1. Advertising

  2. 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
    A.M. Kuchling, Mar 7, 2004
    #2
    1. Advertising

  3. A.M. Kuchling wrote:
    > Content-Disposition: inline; filename="paid-for-download.zip"

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

    --Irmen
    Irmen de Jong, Mar 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmF2aSBK?=

    Pushing a file to the user..

    =?Utf-8?B?UmF2aSBK?=, Mar 2, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,667
    William F. Robertson, Jr.
    Mar 3, 2005
  2. pxlpluker

    Pushing file name to browser

    pxlpluker, Mar 5, 2004, in forum: Python
    Replies:
    0
    Views:
    255
    pxlpluker
    Mar 5, 2004
  3. pxlpluker

    Pushing file name to browser

    pxlpluker, Mar 6, 2004, in forum: Python
    Replies:
    1
    Views:
    257
    Irmen de Jong
    Mar 6, 2004
  4. graham.reeds
    Replies:
    9
    Views:
    1,092
    Pavel Lepin
    Feb 4, 2008
  5. Bertrand

    Using response.addheader for pushing file

    Bertrand, Nov 11, 2003, in forum: ASP General
    Replies:
    0
    Views:
    110
    Bertrand
    Nov 11, 2003
Loading...

Share This Page