From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
Base64ToFile is a function used in Clomosy to convert a Base64 string to a file. This function allows writing a Base64 string to the desired file path by either creating a new file or overwriting the content of an existing file.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
procedure Clomosy.Base64ToFile(AFileName,ABase64:string);
</div>


Clomosy.'''Base64ToFile'''(AFileName,ABase64:string);
Base64ToFile is a function used in Clomosy to convert a Base64 string to a file. This function allows writing a Base64 string to the desired file path by either creating a new file or overwriting the content of an existing file.<br>


'''Example:'''<br>
<b>Example</b><br>
In the example, an image located in the project file directory is converted to Base64 format and written onto a TclMemo object. Then, this object, containing the image in Base64 format, is used to save a new image to the desired project directory using the Base64ToFile feature.
In the example, an image located in the project file directory is converted to Base64 format and written onto a TclMemo object. Then, this object, containing the image in Base64 format, is used to save a new image to the desired project directory using the Base64ToFile feature.<br>


:'''TRObject Syntax'''
<pre>
  var
    Form1 : TCLForm;
    loadImageButton : TClProButton;
    noteMemo : TclMemo;
  void memoFileToBase64Click;
  {
    noteMemo.Lines.Text = Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
    Clomosy.'''Base64ToFile'''(clPathCombine('newApple.png',Clomosy.AppFilesPath),noteMemo.Lines.Text);
  }
 
  //------ 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;
  }
 
:'''Base Syntax'''
  var
  var
   Form1 : TCLForm;
   Form1 : TCLForm;
   loadImageButton : TClProButton;
   loadImageButton : TClProButton;
   noteMemo : TclMemo;
   noteMemo : TclMemo;
 
  procedure memoFileToBase64Click;
  void memoFileToBase64Click;
  begin
  {
   noteMemo.Lines.Text := Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
   noteMemo.Lines.Text = Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
   Clomosy.Base64ToFile(clPathCombine('newApple.png',Clomosy.AppFilesPath),noteMemo.Lines.Text);
   Clomosy.Base64ToFile(clPathCombine('newApple.png',Clomosy.AppFilesPath),noteMemo.Lines.Text);
  end;
  }
   
   
  //------ Main Code ------
  //------ Main Code ------
  begin
  {
   Form1 := TCLForm.Create(Self);
   Form1 = TCLForm.Create(Self);
   Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
   Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png');
    
    
   noteMemo := Form1.AddNewMemo(Form1,'noteMemo','---');
   noteMemo = Form1.AddNewMemo(Form1,'noteMemo','---');
   noteMemo.Align := alMostTop;
   noteMemo.Align = alMostTop;
   noteMemo.Height := 300;
   noteMemo.Height = 300;
   noteMemo.StyledSettings := ssFamily;
   noteMemo.StyledSettings = ssFamily;
   noteMemo.TextSettings.WordWrap := True;
   noteMemo.TextSettings.WordWrap = True;
   
   
   loadImageButton := Form1.AddNewProButton(Form1,'loadImageButton','Add FileToBase64');
   loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Add FileToBase64');
   loadImageButton.Align := alMostBottom;
   loadImageButton.Align = alMostBottom;
   loadImageButton.Margins.Top := 20;
   loadImageButton.Margins.Top = 20;
   loadImageButton.clProSettings.FontSize := 16;
   loadImageButton.clProSettings.FontSize = 16;
   loadImageButton.clProSettings.FontColor := clAlphaColor.clHexToColor('#ffffff');
   loadImageButton.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
   loadImageButton.clProSettings.BackgroundColor := clAlphaColor.clHexToColor('#6966ff');
   loadImageButton.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#6966ff');
   loadImageButton.clProSettings.RoundHeight := 10;
   loadImageButton.clProSettings.RoundHeight = 10;
   loadImageButton.clProSettings.RoundHeight := 10;
   loadImageButton.clProSettings.RoundHeight = 10;
   loadImageButton.SetclProSettings(loadImageButton.clProSettings);
   loadImageButton.SetclProSettings(loadImageButton.clProSettings);
   Form1.AddNewEvent(loadImageButton,tbeOnClick,'memoFileToBase64Click');
   Form1.AddNewEvent(loadImageButton,tbeOnClick,'memoFileToBase64Click');
    
    
   Form1.Run;
   Form1.Run;
  end;
  }
</pre>
 
<h2> See Also </h2>
* [[Clomosy_Class#File_and_Stream_Handling | File and Stream Handling]]

Revision as of 06:14, 25 October 2024

Base64ToFile is a function used in Clomosy to convert a Base64 string to a file. This function allows writing a Base64 string to the desired file path by either creating a new file or overwriting the content of an existing file.

Example
In the example, an image located in the project file directory is converted to Base64 format and written onto a TclMemo object. Then, this object, containing the image in Base64 format, is used to save a new image to the desired project directory using the Base64ToFile feature.

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

 void memoFileToBase64Click;
 {
   noteMemo.Lines.Text = Clomosy.FileToBase64(clPathCombine('apple.png',Clomosy.AppFilesPath));
   Clomosy.Base64ToFile(clPathCombine('newApple.png',Clomosy.AppFilesPath),noteMemo.Lines.Text);
 }
 
 //------ 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