Re: How to specify the name of a downloaded file (IdHttpServer)

Giganews Newsgroups
Subject: Re: How to specify the name of a downloaded file (IdHttpServer)
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Mon, 23 Jul 2007

"Thomas Bergerot" <nospam@nospam.fr> wrote in message
news:A5429E41BC2EE340nospam@nospam.fr...

> Using a TIdHttpServer, i use OnCommandGet(), and send
> a file using ServeFile().

You did not say which version of Indy you are using.

> The problem is the requested url is http://localhost/pimpmyfile,
> and the file is automatically named "pimpmyfile" by firefox.

That is because there is no filename being provided in the response headers,
so the browser (any browser, not just FireFox) will use the filename from
the original URL.

> How can i tell firefox the new name of my dowloaded file ?

You need to set the "Content-Disposition" response header before calling
ServeFile(), ie:

    AResponse.CustomHeaders.Values['Content-Disposition'] :=
Format('attachment; filename="%s"', [TheFileNameHere]);

> I tried AResponseInfo.Location, without success.

That property has nothing to do with this issue.

Gambit

Replies

In response to

How to specify the name of a downloaded file (IdHttpServer) posted by Thomas Bergerot on Sun, 22 Jul 2007