Sample code for 30+ languages & platforms
Delphi ActiveX

Box.com Download Binary File to Memory

See more Box Examples

Retrieves the actual data of the file into a memory (not to a local file).

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
http: TChilkatHttp;
bd: TChilkatBinData;
statusCode: Integer;

begin
success := 0;

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

http := TChilkatHttp.Create(Self);
http.KeepResponseBody := 1;

// Provide a previously obtained OAuth2 access token.
// See Get Box OAuth2 Access Token.
http.AuthToken := 'BOX_ACCESS_TOKEN';

http.FollowRedirects := 1;

// The file is specified by the file ID.
// In this case, we're downloading a file with FILE_ID = 283371752129.
// The general form of the URL for downloading is: https://api.box.com/2.0/files/FILE_ID/content
bd := TChilkatBinData.Create(Self);
success := http.DownloadBd('https://api.box.com/2.0/files/283371752129/content',bd.ControlInterface);
statusCode := http.LastStatus;
if (success = 0) then
  begin
    if (statusCode = 0) then
      begin
        // Unable to either send the request or get the response.
        Memo1.Lines.Add(http.LastErrorText);
      end
    else
      begin
        // We got a response, but the status code was not in the 200s
        Memo1.Lines.Add('Response status code: ' + IntToStr(statusCode));
        // Examine the response body.
        Memo1.Lines.Add('Response body:');
        Memo1.Lines.Add(http.LastResponseBody);
      end;
    Memo1.Lines.Add('Download failed.');

  end
else
  begin
    Memo1.Lines.Add('Downloaded tigers.jpeg into an object holding the binary data.');

    Memo1.Lines.Add('Number of bytes: ' + IntToStr(bd.NumBytes));
  end;
end;