(Delphi DLL) Get Contents of File as Base64
Demonstrates how to read the contents of a file and convert to a base64 string.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData;
...
procedure TForm1.Button1Click(Sender: TObject);
var
bd: HCkBinData;
success: Boolean;
begin
bd := CkBinData_Create();
success := CkBinData_LoadFile(bd,'qa_data/jpg/starfish.jpg');
if (success = False) then
begin
Memo1.Lines.Add('Failed to load file.');
Exit;
end;
Memo1.Lines.Add(CkBinData__getEncoded(bd,'base64'));
// If you want mult-line base64:
Memo1.Lines.Add('--');
Memo1.Lines.Add(CkBinData__getEncoded(bd,'base64_mime'));
// If you want hex..
Memo1.Lines.Add('--');
Memo1.Lines.Add(CkBinData__getEncoded(bd,'hex'));
// etc.
CkBinData_Dispose(bd);
end;
|