Delphi ActiveX
Delphi ActiveX
WhatsApp - Download/Retrieve Media
Demonstrates how to download media previously uploaded to the WhatsApp Business API clientChilkat Delphi ActiveX Downloads
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;
bdResponseBody: TChilkatBinData;
respStatusCode: Integer;
begin
success := 0;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
// Implements the following CURL command:
// curl -X GET \
// https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f \
// -H 'Authorization: Bearer your-auth-token' \
// -o path/filename
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Adds the "Authorization: Bearer your-auth-token" header.
http.AuthToken := 'your-auth-token';
bdResponseBody := TChilkatBinData.Create(Self);
success := http.QuickGetBd('https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f',bdResponseBody.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
respStatusCode := http.LastStatus;
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
Memo1.Lines.Add('response header = ' + http.LastResponseHeader);
if (respStatusCode <> 200) then
begin
Memo1.Lines.Add('Error response body:');
Memo1.Lines.Add(bdResponseBody.GetString('utf-8'));
Exit;
end;
success := bdResponseBody.WriteFile('path/filename');
end;