(Delphi ActiveX) Base64 Encode a File
Delphi ActiveX to Base64 encode the contents of a file.
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
fac: TCkFileAccess;
strBase64: WideString;
success: Integer;
begin
// Get the contents of a file into a base64 encoded string:
fac := TCkFileAccess.Create(Self);
strBase64 := fac.ReadBinaryToEncoded('c:/data/something.pdf','base64');
if (fac.LastMethodSuccess <> 1) then
begin
Memo1.Lines.Add(fac.LastErrorText);
Exit;
end;
// Now write the string to a file:
success := fac.WriteEntireTextFile('c:/data/something_pdf_base64.txt',strBase64,'us-ascii',0);
if (success <> 1) then
begin
Memo1.Lines.Add(fac.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Success!');
end;
|