?
Solved

Indy HTTP

Posted on 2002-05-23
3
Medium Priority
?
271 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

718 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