Am trying to convert picture to bigtext or base64. Again On xmlport am trying convert text to stream and save it in field of Mediaset type.?
but it is not working
i get the following error
Please help
Am trying to convert picture to bigtext or base64. Again On xmlport am trying convert text to stream and save it in field of Mediaset type.?
but it is not working
i get the following error
Please help
Hi,
If it’s any help, we put here two functions, related with Media Type, Media Set Table and the codeunit for convert to base64. The functions use RecordRefs and a list to inform some fields of Media Set Table.
local procedure EncodeFieldMediaToBase64(RefFieldRef: FieldRef; var TextBigText: BigText; var InfoMediaText: Text)
//Convert a Media to a base 64 big text. The FieldRef is Media type.
var
TenantMediaRec: Record “Tenant Media”;
Base64Convert: codeunit “Base64 Convert”;
MediaGuid: Guid;
isInstream: InStream;
begin
Clear(TextBigText);
MediaGuid := RefFieldRef.Value;
if TenantMediaRec.Get(MediaGuid) then begin
TenantMediaRec.CALCFIELDS(Content);
if TenantMediaRec.Content.HASVALUE() then begin
GetRestFieldsTenantMedia(TenantMediaRec, InfoMediaText); <- Only retrieve other fields of Media Set...
TenantMediaRec.Content.CREATEINSTREAM(isInstream);
TextBigText.AddText(Base64Convert.ToBase64(isInstream));
end;
end;
end;
local procedure DecodeFieldMediaFromBase64(var RefFieldRef: FieldRef; var TextBigText: BigText; InfoMediaText: Text)
//Convert a text base 64 to Media (blob).
var
TenantMediaRec: Record “Tenant Media”;
Base64Convert: codeunit “Base64 Convert”;
osOutStream: OutStream;
InfoMediaList: List of [Text];
begin
TenantMediaRec.Init();
TenantMediaRec.ID := CreateGuid();
TenantMediaRec.Content.CreateOutStream(osOutStream);
Base64Convert.FromBase64(format(TextBigText), osOutStream);
if InfomediaText <> '' then begin
InfoMediaList := InfoMediaText.Split('|');
TenantMediaRec.Description := format(InfoMediaList.Get(1));
TenantMediaRec."File Name" := format(InfoMediaList.Get(2));
TenantMediaRec."Mime Type" := format(InfoMediaList.Get(3));
TenantMediaRec."Creating User" := format(InfoMediaList.Get(4));
if format(InfoMediaList.Get(5)) <> '' then
evaluate(TenantMediaRec."Expiration Date", InfoMediaList.Get(5));
if format(InfoMediaList.Get(6)) <> '' then
evaluate(TenantMediaRec."Prohibit Cache", InfoMediaList.Get(6));
if format(InfoMediaList.Get(7)) <> '' then
evaluate(TenantMediaRec.Width, InfoMediaList.Get(7))
else
TenantMediaRec.Width := 0;
if format(InfoMediaList.Get(8)) <> '' then
evaluate(TenantMediaRec.Height, InfoMediaList.Get(8))
else
TenantMediaRec.Height := 0;
TenantMediaRec."Company Name" := CopyStr(CompanyName(), 1, MaxStrLen(TenantMediaRec."Company Name"));
end;
if not TenantMediaRec.Insert() then
TenantMediaRec.Modify();
RefFieldRef.Value := TenantMediaRec.ID;
end;
I hope it’s useful.
Best wishes!
Thank you very much for your kind refrence. It helped me alot sir!.
In Case of NAv2018, I dont find CDU -Base64 Convert , How to replicate the same in That .
Please clarify!
Hi,
You can search about Convert to Base64 codeunits for Dynamics Nav made for other developers in internet.
I don’t know if I can do mention of other forums here. But you can even download any codeunit from others more classic and old forums.
My Best wishes!