Streaming binary files to clients over HTTP
Hi
I have an Indy HTTP server driving a webbroker app and want to send binary
files down to an IE client.
What is the easiest way to do this?
My web dispatcher action is currently
var
queryFields: TStringList;
filename: string;
filenameItem: integer;
fStream: TFileStream;
sStream: TStringStream;
q: string;
begin
queryFields:= TStringList.Create;
try
Request.ExtractQueryFields(queryFields);
q:= queryFields.Text;
if (queryFields.Count=1) then
begin
// content is of for file=XXXX
fileName:= Copy(queryFields.Strings[0],6,255);
if (fileName<>'') and FileExists(fileName) then
begin
fStream:= TFileStream.Create(fileName,fmOpenRead or
fmShareDenyNone);
try
Response.ContentType:= 'application/octet-stream';
fStream.Seek(0,0);
Response.SendStream(fStream);
finally
fStream.Free;
end;
end;
end;
Handled:= true;
finally
queryFields.Free;
end;
end;
but this gets displayed literally in the browser window whereas I want it to
display it's open/save dialog.
TIA
Richard