Board index » delphi » problem loading pictures of web page using TidHTTPServer and TPageProducer

problem loading pictures of web page using TidHTTPServer and TPageProducer


2006-06-28 09:08:04 AM
delphi172
Following is some code I am using to fill in Tags from a web page - then
send it using TidHTTPServer.
Im not sure if this is the best way of doing this but I cant get it to work
at all.
If there is a better way of filling in tags then please let me know cause as
you can see I am having to save out to the tempary file.
htmlPageProducer: TPageProducer;
HTTPServer: TIdHTTPServer;
if FileExists(LocalDoc) then // File exists
begin
htmlPageProducer.HTMLFile:= LocalDoc;
TempFileName:= ChangeFileExt(LocalDoc, '.tmp');
TempFile:= TStringList.Create;
try
TempFile.Add(htmlPageProducer.Content);
TempFile.SaveToFile(TempFileName);
finally
TempFile.Destroy;
end;
HTTPServer.ServeFile(AThread, AResponseInfo, TempFileName);
end;
Problem is that images are not being displayed.
If i use
HTTPServer.ServeFile(AThread, AResponseInfo, LocalDoc);
all works fine
Thanx in advance.
 
 

Re:problem loading pictures of web page using TidHTTPServer and TPageProducer

"Glen Welch" <XXXX@XXXXX.COM>writes
Quote
Following is some code I am using to fill in Tags from a web page -
then send it using TidHTTPServer. Im not sure if this is the best way
of doing this but I cant get it to work at all. If there is a better way
of
filling in tags then please let me know cause as you can see I am
having to save out to the tempary file.
The TIdHTTPResponseInfo parameter of the TIdHTTPServer.OnCommandGet event
handler has ContentStream and ContentText properties. You can use those
instead of a file, ie:
procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHttpResponseInfo);
begin
//...
if FileExists(LocalDoc) then
begin
htmlPageProducer.HTMLFile := LocalDoc;
AResponseInfo.ContentText := htmlPageProducer.Content;
AResponseInfo.ContentType := 'text/html';
end;
//...
end;
Quote
Problem is that images are not being displayed.
That would happen if either 1) the <img>tags are malformed to begin with,
or else 2) your TIdHTTPServer code is not handling the image requests
properly. Please show a more complete code snippet of what you are actually
doing.
Gambit
 

Re:problem loading pictures of web page using TidHTTPServer and TPageProducer

"Glen Welch" <XXXX@XXXXX.COM>writes
Quote
This is the only coding I have - sorry only new to using
the http server so am probably missing something...
When the webbrowser wants to download an image for a page, it has to send a
new request to the server. You are passing the requested image path back to
the page producer, rather than serving up the image file directly. You need
to look at the requested file path and then decide how best to handle it, on
a per-file basis.
For that matter, why are you using the page producer at all? Why not just
serve the HTML files directly? You can not use a page producer to generate
non-HTML files.
Quote
The page index.htm was written using Front Page and contains 3
images that do not display when the page is loaded into IE
That is because you are not handling the image files properly at all.
Quote
when I use HTTPServer.ServeFile(AThread, AResponseInfo, LocalDoc)
all works fine.
Of course it does, because you are serving the actual files as-is from the
hard drive without any processing on them. If the files exist, the raw data
is sent to the browser as-is. That is not the case when you try to use the
page producer and ignore non-HTML files, which you are currently doing.
Gambit