Solved

Indy HTTP

Posted on 2002-05-23
3
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 121
Working with hours 3 74
How to Get Images From Server to Client using App Tethering 1 41
MS Access from Delphi 31 81
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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