I have an encoded64 string parameter of a RO server method (representing a png file) which I would like to save in a file.
My first attempt was to just save it. It saved OK but no one could use it (as it was not native format, just a bunch of characters).
So, I converted it using this function:
uses
System.NetEncoding, System.Classes, System.SysUtils;
function ConvertBase64EncodedPNGToBinary(const Base64String: string): TByteStream;
var
DecodedStream: TBytesStream;
EncodedBytes: TBytes;
begin
// Convert the Base64 string to bytes
EncodedBytes := TNetEncoding.Base64.DecodeStringToBytes(Base64String);
// Create a stream from the decoded bytes
result := TBytesStream.Create(EncodedBytes);
end;
My server function (the function that will save it to a file) is the following:
Delphi complains that incompatible format TRoMemoryBinaryStream and TBytesStream. The problem is I don’t know how to feed a TRoMemoryBinaryStream (Binary) with a TBytes (decoded64) array.