Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Http.S3_DownloadBd method

See more Amazon S3 Examples

Demonstrates the S3_DownloadBd method.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.BinData,
  Chilkat.Http;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  bucketName: string;
  objectName: string;
  localFilePath: string;
  bd: TBinData;

begin
  success := False;

  //  This requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  http := THttp.Create;

  http.AwsAccessKey := 'AWS_ACCESS_KEY';
  http.AwsSecretKey := 'AWS_SECRET_KEY';
  http.AwsRegion := 'us-west-2';
  http.AwsEndpoint := 's3-us-west-2.amazonaws.com';

  bucketName := 'chilkat.qa';
  objectName := '/images/sea_creatures/starfish.jpg';
  localFilePath := 'qa_output/starfish.jpg';

  bd := TBinData.Create;
  success := http.S3_DownloadBd(bucketName,objectName,bd);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  WriteLn('Downloaded ' + bd.NumBytes + ' bytes');


  http.Free;
  bd.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.