More about HTTPget

lundorff
lundorff used Ask the Experts™
on
1) Is there a way to determind the filesize of a file before downloading it?

Rgs
Lund
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
please be more specific...
what file you mean, and direction - upload to server/download from client ?

Author

Commented:
Oh sorry please read this http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20398745.html

I want to know if I can use the HTTPget component to easily determind the filesize of a file stored in the HTTPget1.?

Author

Commented:
I just took a look at the indy-component IdHTTP and it does has the size-function I need. How do I get a list of alle the links on a given page using the Indy component instead?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
I just took a look at the indy-component IdHTTP and it does has the size-function I need. How do I get a list of alle the links on a given page using the Indy component instead?

Author

Commented:
I just took a look at the indy-component IdHTTP and it does has the size-function I need. How do I get a list of alle the links on a given page using the Indy component instead?

Author

Commented:
I just took a look at the indy-component IdHTTP and it does has the size-function I need. How do I get a list of alle the links on a given page using the Indy component instead?

Author

Commented:
let me see now.. this piece of code

procedure TForm1.Button4Click(Sender: TObject);
var
    test: TFileStream;
    size: integer;
begin
test := TFileStream.Create('c:\logo.mpeg',fmcreate);
IndyHTTP.Get('http://domain.com/logo.jpg',test);
test.Free
end;

will let me download the picture "logo.jpg" form domain.com but if I want to know the size of "logo.jpg" I must write the following before I download:

IndyHTTP.Head('http://domain.com/logo.jpg');
size := IndyHTTP.Response.ContentLenght;

The problem is that I acutally is downloading the picture twice in order to check it......... how do I check the filesize with downloading the file?

Rgs
Lund

Commented:
Hi lundorff!

This is my prefered function:

function GetInternetFileSize(url: String): String;
var
  session, theFile: hInternet;
  index, codeLen: Cardinal;
  code: array[1..20] of char;
  res: pchar;
begin
  if pos('http://',lowercase(url)) = 0 then url := 'http://' + url;
  Session := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if assigned(session) then
  begin
     theFile := InternetOpenUrl(session, pchar(url), nil, 0, INTERNET_FLAG_RELOAD, 0);
     Index:= 0;
     CodeLen:= 10;
     HttpQueryInfo(theFile, HTTP_QUERY_CONTENT_LENGTH, @code, codeLen, Index);
     res:= PChar(@code);
     if (res = '245') then res:= '-1';
     if assigned(theFile) then InternetCloseHandle(theFile);
  end;
  InternetCloseHandle(session);
  GetInternetFileSize:= res;
end;

Markus

Author

Commented:
Hallo,
what do I need to declare in users in order to use "hInternet"? Im using Delphi 6

Rgs
Lund

Author

Commented:
Hallo,
what do I need to declare in users in order to use "hInternet"? Im using Delphi 6

Rgs
Lund

Author

Commented:
Works like a charm thx :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial