Solved

Indy HTTP

Posted on 2002-05-23
3
263 Views
Last Modified: 2010-04-04
Hi, Im using the Indy HTTP client in D6. Is there an easy way to check if an URL points to a binary file? I would like to skip links pointing to binary files.

Thanks
0
Comment
Question by:pede
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
aubs earned 50 total points
ID: 7029850
You could use the Head method and analyse the contentType to see what sort of file it is:


HTTP := TIdHTTP.Create(nil);
  with HTTP do
try
      Head(URL_in_question);
      FileType := Response.ContentType;
      if Pos('text', LowerCase(FileType)) = 0 then //a file - not a text/html page
...

Aubs

0
 
LVL 2

Expert Comment

by:aubs
ID: 7029866
An alternative is to look at the URL extension:


Type TFileType=(ftUnknown, ftImage, ftPage, ftZip, ftMovie, ftReal, ftPDF, ftExe);

...

function ReverseString(StrIn: String): String;
var
  i: integer;
  revStr: String;
begin
     revStr:= '';
  for i:= length(StrIn) downto 1 do
    revStr:= revStr + StrIn[i];
  Result:= revStr;
end;

function FileType(URL: String): TFileType;
begin
  URL:= ReverseString(URL);
  URL:= Copy(URL, 1, Pos('.',URL) - 1);
  URL:= lowerCase(ReverseString(URL));
  if Pos(URL, 'html txt')>0 then
       Result:= ftPage
  else if Pos(URL, 'gif jpg bmp jpeg')>0 then
       Result:= ftImage
  else if Pos(URL, 'zip')>0 then
       Result:= ftZip
  else if Pos(URL, 'mpg mpeg avi mov')>0 then
       Result:= ftMovie
  else if Pos(URL, 'rm')>0 then
       Result:= ftReal
  else if Pos(URL, 'pdf')>0 then
       Result:= ftPDF
  else if Pos(URL, 'exe')>0 then
       Result:= ftExe

  else
    Result:= ftUnknown;
end;

...

    if  FileType = ftPage then //html page
       getPage()....
    else if  FileType = ftMovie then
       getMovieFile()...

etc.


Aubs


0
 
LVL 1

Author Comment

by:pede
ID: 7031571
Great! Exactly what I needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 105
How to renew a Delphi rad-studio licence? 5 49
How to define IfThen functions in one common unit? 4 44
Dev express lookupcombo 3 13
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now