(Delphi ActiveX) Download Image (JPG, GIF, etc.) to Base64
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.
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
http: TChilkatHttp;
bd: TChilkatBinData;
success: Integer;
base64_image_data: WideString;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
bd := TChilkatBinData.Create(Self);
success := http.DownloadBd('https://www.chilkatsoft.com/images/starfish.jpg',bd.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
base64_image_data := bd.GetEncoded('base64');
Memo1.Lines.Add('image data in base64 format:');
Memo1.Lines.Add(base64_image_data);
end;
|