Solved

Indy HTTP

Posted on 2002-05-23
3
262 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

13 Experts available now in Live!

Get 1:1 Help Now