From Clomosy Docs
function Clomosy.StreamToBase64(AStream:TclMemoryStream):string;
In Clomosy, StreamToBase64 is a function used to convert a data stream (TCLMemoryStream) to Base64 format. Base64 is an encoding scheme used to convert binary data into text format. This method allows data to be securely transmitted or stored via text-based protocols such as email or JSON.
Example
Below is an example code snippet in Clomosy that converts a TclMemoryStream object to Base64 format. In the example, an image obtained from a file is converted to a TclMemoryStream, and this converted structure is then transformed into Base64 format and stored in a string object.
var Form1 : TCLForm; loadImageButton : TClProButton; Img1 : TCLImage; memoryStream : TCLMemoryStream; base64String,saveFileName : String; void ConvertMemoryStreamToBase64 { if (memoryStream.Size > 0) // Checking whether the memoryStream content is empty or not { base64String = Clomosy.StreamToBase64(memoryStream); // Convert TclMemoryStream to Base64 //saveFileName = clPathCombine('apple.png', Clomosy.AppFilesPath); //Clomosy.Base64ToFile(saveFileName,base64String); // Saves data in base64 with the given extension. } else ShowMessage('MemoryStream Empty'); } void loadImageButtonClick var MyFileStr : String; { MyFileStr = clPathCombine('apple.png', Clomosy.AppFilesPath); if clFileExists('apple.png', Clomosy.AppFilesPath) { memoryStream = Clomosy.FileToStream(MyFileStr); Img1.Bitmap.LoadFromStream(memoryStream); //Img1.Bitmap.LoadFromFile(MyFileStr); ShowMessage('Image Uploaded.'); ConvertMemoryStreamToBase64; } else ShowMessage('No File'); } //------ Main Code ------ { Form1 = TCLForm.Create(Self); Form1.AddAssetFromUrl('https://clomosy.com/demos/apple.png'); MemoryStream = TclMemoryStream.Create; Img1 = Form1.AddNewImage(Form1,'Img1'); Img1.Width = 100; Img1.Height = 100; loadImageButton = Form1.AddNewProButton(Form1,'loadImageButton','Upload Image'); 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,'loadImageButtonClick'); Form1.Run; }