Jump to content
Sign in to follow this  
alnickels

Soap Server and client downloading files

Recommended Posts

Does anybody know where I can find an example of a  delphi client and server that will download binary files of size 250k or more using soap?

Share this post


Link to post

Just let the server provide the client with a download link. Using soap to download data is quite cumbersome in my experience. Cumbersome meaning slow...and you might even need to convert binary data to a readable format like base64 server side and reconvert client side, costing more performance.

Share this post


Link to post

Convert the binary data to base64-encoded string and return it to the client which can decode it back to binary. In my experience, passing 2-5 megabytes this way does not cause any problems.

Share this post


Link to post

Hi,

 

These codes I have tested ok.

 

Server Side:

unit TestAttachImpl;
 
interface
 
uses Soap.InvokeRegistry, System.Types, System.SysUtils, Soap.XSBuiltIns, TestAttachIntf;
 
type
 
  { TTestAttach }
  TTestAttach = class(TInvokableClass, ITestAttach)
  public
    procedure GetAttach(var FileName: string; out Attach: TSOAPAttachment); stdcall;
    procedure PutAttach(const FileName: string; Attach: TSOAPAttachment); stdcall;
  end;
 
implementation
 
 
{ TTestAttach }
 
procedure TTestAttach.GetAttach(var FileName: string; out Attach: TSOAPAttachment);
var
  Fn: string;
begin
  //Send file to client
  Fn := 'F:\H264Output.mp4';
 
  Attach := TSOAPAttachment.Create;
  Attach.SetSourceFile(Fn);
  FileName := ExtractFileName(Fn);
end;
 
procedure TTestAttach.PutAttach(const FileName: string;
  Attach: TSOAPAttachment);
begin
  //receive file that client upload
  Attach.SaveToFile(ExtractFilePath(GetModuleName(0)) + FileName);
end;
 
initialization
{ Invokable classes must be registered }
   InvRegistry.RegisterInvokableClass(TTestAttach);
end.

 

 

Client-side:


procedure TForm2.Button1Click(Sender: TObject);
var
  Attach: TSOAPAttachment;
  Intf: ITestAttach;
  Path, Fn: string;
begin
  //client download file
  Path := ExtractFilePath(Application.ExeName);
  Attach := TSOAPAttachment.Create;
  Intf := HTTPRIO1 as ITestAttach;
  try
    Intf.GetAttach(Fn, Attach);
    Attach.SaveToFile(Path + Fn);
  finally
    Intf := nil;
    Attach.Free;
  end;
 
end;
 
procedure TForm2.Button2Click(Sender: TObject);
var
  Fn: string;
  Attach: TSOAPAttachment;
  Intf: ITestAttach;
begin
  //client upload file
  if OpenDialog1.Execute then
  begin
    Fn := OpenDialog1.FileName;
 
    Attach := TSOAPAttachment.Create;
    Attach.SetSourceFile(Fn);
    Intf := HTTPRIO1 as ITestAttach;
    try
      Intf.PutAttach(ExtractFileName(Fn), Attach);
    finally
      Intf := nil;
      Attach.Free;
    end;
  end;
end;

 

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
Sign in to follow this  

×