Hi all.
I am currently working with an import of a file in BC, where the file is a Base64 string, which i am placing in a media field in a Table.
It seems to me that the older version of convert, works ok here, but not the new codeunit..
the old conversion I used, is part of the TempBLOB table, which is discontinued in V19. the procedure I refer to here is FromBase64, and it seem to work OK.
The newer codeunit 'Convert Base64' has the similar procedure 'FromBase64', and is intended to replace the older Table code.
Now this again, produces a binary streing, and I get a value in my media field, but the data seem to be somehow corrupt here. (I use PDF files to show, and the come as blank pages)
Here is my code for the old, working version example:
var Base64Value, is a text string which contain the Base64 string of a pdf file.
var
attachBlob: Record "TempBlob";
attachOut: OutStream;
attachIn: InStream;
FileName := 'File.pdf';
AttachBlob.Blob.CreateInStream(attachIn);
AttachBlob.Blob.CreateOutStream(attachOut);
attachBlob.FromBase64String(Base64Value);
media.keyId := media.MediaStream.ImportStream(attachIn, mergedFileName, 'application/pdf');
media.Name := mergedFileName;
media.Size := attachBlob.Length();
media.Insert();
Here is my code for the new version example, not working, in my opinion:
var
base64: Codeunit "Base64 Convert";
attachBlob: Codeunit "Temp Blob";
attachOut: OutStream;
attachIn: InStream;
FileName := 'File.pdf';
AttachBlob.CreateInStream(attachIn);
AttachBlob.CreateOutStream(attachOut);
attachOut.Write(base64.FromBase64(Base64Value));
media.keyId := media.MediaStream.ImportStream(attachIn, mergedFileName, 'application/pdf');
media.Name := mergedFileName;
media.Size := attachBlob.Length();
media.Insert();
Have anyone else touched this issue?
Best Regards
Glenn