Sample code for 30+ languages & platforms
Delphi ActiveX

Convert any File to Base64 (and back)

Demonstrates how to get the contents of any file as a base64 string, and then write it back.

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;
bd: TChilkatBinData;
b64Str: WideString;
bd2: TChilkatBinData;

begin
success := 0;

bd := TChilkatBinData.Create(Self);

// This example will load a PDF and return it as a base64 string.
success := bd.LoadFile('qa_data/pdf/helloWorld.pdf');
if (success <> 1) then
  begin
    Memo1.Lines.Add('Failed to load file.');
    Exit;
  end;

b64Str := bd.GetEncoded('base64');
Memo1.Lines.Add(b64Str);

// Now write the base64 string back to the binary PDF file:
bd2 := TChilkatBinData.Create(Self);
success := bd2.AppendEncoded(b64Str,'base64');
success := bd2.WriteFile('qa_output/helloWorld.pdf');
end;