programatically get the file size from a remote file using delphi, before download it

delphi

Solution

You could use Indy.

First include `IdHTTP`.

You can retrieve the size this way:

procedure TFormMain.Button1Click(Sender: TObject);
var
  Http: TIdHTTP;
begin
  Http := TIdHTTP.Create(nil);
  try
    Http.Head('http://live.sysinternals.com/ADExplorer.exe');

    ShowMessage(IntToStr(Http.Response.ContentLength));
  finally
    Http.Free;
  end;
end;

Problem

How i can determine the size in bytes of a remote file hosted in the web, before download it, using Delphi? Thanks In advance.

Original source