From Clomosy Docs

(Created page with "FileToBase64 is a function used in Clomosy to convert the content of a file to Base64 format. This function reads the content of a file, loads it into a TclMemoryStream object in memory, and then converts this stream to Base64 format. Clomosy.'''FileToBase64'''(AFileName:string):string; '''Example:'''<br> In the example, when a button is clicked, it writes an image obtained from the project files to a TclMemo object in Base64 format. var Form1 : TCLForm; l...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
FileToBase64 is a function used in Clomosy to convert the content of a file to Base64 format. This function reads the content of a file, loads it into a TclMemoryStream object in memory, and then converts this stream to Base64 format.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function Clomosy.FileToBase64(AFileName:string):string;
</div>


  Clomosy.'''FileToBase64'''(AFileName:string):string;
FileToBase64 is a function used in Clomosy to convert the content of a file to Base64 format. This function reads the content of a file, loads it into a TclMemoryStream object in memory, and then converts this stream to Base64 format.<br>


'''Example:'''<br>
<b>Example</b><br>
In the example, when a button is clicked, it writes an image obtained from the project files to a TclMemo object in Base64 format.
In the example, when a button is clicked, it writes an image obtained from the project files to a TclMemo object in Base64 format.<br>


  var
<pre>
    Form1 : TCLForm;
var
    loadImageButton : TClProButton;
  Form1 : TCLForm;
    noteMemo : TclMemo;
  loadImageButton : TClProButton;
  noteMemo : TclMemo;
 
void memoFileToBase64Click;
{
  noteMemo.Lines.Text = Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
}
 
//------ Main Code ------
{
  Form1 = TCLForm.Create(Self);
  Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
 
  noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
  noteMemo.Align = alMostTop;
  noteMemo.Height = 300;
  noteMemo.StyledSettings = ssFamily;
  noteMemo.TextSettings.WordWrap = True;
   
   
  void memoFileToBase64Click;
  loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Add FileToBase64');
  {
  loadImageButton.Align = alMostBottom;
    noteMemo.Lines.Text = Clomosy.'''FileToBase64'''(clPathCombine('apple.png',Clomosy.AppFilesPath));
  loadImageButton.Margins.Top = 20;
  }
  loadImageButton.clProSettings.FontSize = 16;
  loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
  //------ Main Code ------
  loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff');
  {
  loadImageButton.clProSettings.RoundHeight = 10;
    Form1 = TCLForm.Create(Self);
  loadImageButton.clProSettings.RoundHeight = 10;
    Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
  loadImageButton.SetclProSettings(loadImageButton.clProSettings);
   
  Form1.AddNewEvent(loadImageButton,tbeOnClick,'memoFileToBase64Click');
    noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
 
    noteMemo.Align = alMostTop;
  Form1.Run;
    noteMemo.Height = 300;
}
    noteMemo.StyledSettings = ssFamily;
</pre>
    noteMemo.TextSettings.WordWrap = True;
 
 
<h2> See Also </h2>
    loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Add FileToBase64');
* [[Clomosy_Class#File_and_Stream_Handling | File and Stream Handling]]
    loadImageButton.Align = alMostBottom;
{{#seo:|title=FileToBase64 in Clomosy - Clomosy Docs}}
    loadImageButton.Margins.Top = 20;
{{#seo:|description=Explore FileToBase64 in Clomosy! A step-by-step guide to converting files into Base64 format for enhanced data processing in your apps.}}
    loadImageButton.clProSettings.FontSize = 16;
    loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
    loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff');
    loadImageButton.clProSettings.RoundHeight = 10;
    loadImageButton.clProSettings.RoundHeight = 10;
    loadImageButton.SetclProSettings(loadImageButton.clProSettings);
    Form1.AddNewEvent(loadImageButton,tbeOnClick,'memoFileToBase64Click');
   
    Form1.Run;
  }

Latest revision as of 12:56, 24 December 2024

FileToBase64 is a function used in Clomosy to convert the content of a file to Base64 format. This function reads the content of a file, loads it into a TclMemoryStream object in memory, and then converts this stream to Base64 format.

Example
In the example, when a button is clicked, it writes an image obtained from the project files to a TclMemo object in Base64 format.

 var
   Form1 : TCLForm;
   loadImageButton : TClProButton;
   noteMemo : TclMemo;

 void memoFileToBase64Click;
 {
   noteMemo.Lines.Text = Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
 }

 //------ Main Code ------
 {
   Form1 = TCLForm.Create(Self);
   Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
   
   noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
   noteMemo.Align = alMostTop;
   noteMemo.Height = 300;
   noteMemo.StyledSettings = ssFamily;
   noteMemo.TextSettings.WordWrap = True;
 
   loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Add FileToBase64');
   loadImageButton.Align = alMostBottom;
   loadImageButton.Margins.Top = 20;
   loadImageButton.clProSettings.FontSize = 16;
   loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
   loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff');
   loadImageButton.clProSettings.RoundHeight = 10;
   loadImageButton.clProSettings.RoundHeight = 10;
   loadImageButton.SetclProSettings(loadImageButton.clProSettings);
   Form1.AddNewEvent(loadImageButton,tbeOnClick,'memoFileToBase64Click');
   
   Form1.Run;
 }

See Also