ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

New handling for Base64 encoding breaks file.

Open sirhc101 opened this issue 7 years ago • 1 comments

Hello there,

first of all, sorry for the confusing title. Of course I know, that you've moved ToBase64String() to ToBase64() method in Base64 Convert codeunit. Nice Idea, but I ran into a problem here.

Let me outline: I need to upload a certificate file (pfx) to Business Central and store it in a blob field. This certificate file I need to send by web service (JSON) request as a base64 converted string. Previously I uploaded the file and when I needed to send it I copied the blob to the TempBlob table and used the ToBase64String method to get the base64 string back. Well if I do this now, I need to write me pfx file from the blob field to a Text variable and then using Base64 Convert codeunit to get the encoded string back. Unfortunetly this breaks me file and is resulting in an incorrect base64 string. I guess the field value gets broken because I've to store the blob content in a text variable before converting it.

It's pretty easy to reproduce the problem:

[..]
// upload file and store to blob field
with myTable do begin
  fileMgmt.BLOBImportWithFilter(TempBlobCodeunit, SelectFileMsg, '', FileFilterTxt, 'pfx');
  tempBlobCodeunit.CreateInStream(streamIn);
  "My Blob Field".CreateOutStream(streamOut);
  CopyStream(streamOut, streamIn);
  modify(true);
end;

// convert file in blob to base64 string
"My Blob Field".CreateInStream(stream);
while (not stream.EOS) do begin
  stream.ReadText(portion); // I think here it gets broken!
  fieldValue += portion;
end;

base64String := base64Convert.ToBase64(fieldValue);
[...]

In my opinion the best option to solve this would be you add an overloaded method ToBase64 and FromBase64 with Temp Blob codeunit as parameter and convert the blob value, like TempBlob.ToBase64String() did before.

Because this problem is breaking two of my apps it would be nice if you can solve this as soon as possible.

Thanks in advance.

sirhc101 avatar Oct 06 '19 17:10 sirhc101

My fault!! I didn't mentioned the ToBase64(InStream: InStream) overload.

Case closed ;-)

sirhc101 avatar Oct 06 '19 18:10 sirhc101