Jump to content
Clément

Using TSslHttpAppSrv to download a Binary file

Recommended Posts

Posted (edited)

Hello,

 

I'm using 8.69, I can't update right now, and Delphi 12.1.

 

I wrote a TUrlHandle child class to handle download of binary files. In this case zrnbw file. 
I'm unable to figure out how to do it. I'm missing  a lot of things.
With this code, any client application that connects to my appServer hangs after sending the download request.

How would be the right way to handle downloading of binary data?

 

TIA

 

procedure THandler_files_UpdateDownload.Execute;
const
   NO_CACHE: String     = 'Pragma: no-cache' + #13#10 + 'Expires: -1' + #13#10;
begin
  inherited;
  var lBasename   : String;
  var lZrnbwFile  := '';
  var lParams     := TStringList.Create('"', '&', [soStrictDelimiter]);
  try
    lParams.DelimitedText := Client.Params;
    lBaseName      := TNetEncoding.URL.Decode( lParams.Values['basename'] );
    lZrnbwFile     := TPath.Combine( glbServerConfig.DefaultUpdate, lBasename+'.zrnbw');
    if FileExists(lZrnbwFile) then
    begin
      DocStream := TFileStream.Create( lZrnbwFile, fmOpenRead );
      AnswerStream('','application/binary',NO_CACHE);

      //Client.DocStream.Free;
    end

  finally
    lParams.free;
  end;
end;


 

Edited by Clément

Share this post


Link to post

Essentially your code is ok, except the first parameter of AnswerStream is var Flags : THttpGetFlag; so can not be left blank.  There is a an extra parameter to pass a last modified date which is friendly for so applications that do a HEAD first to check if the file is newer. 

 

You should free DocStream before creating it, and the server should free it when the request completes.  

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×