web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

How to get base64 string of an image in D365 Business Central

(0) ShareShare
ReportReport
Posted on by 241

Hi experts, how are you all? Hope you all are fine. I'm looking for a way to convert a picture (blob) field into base64.

Suppose I've two fields in a custom table. These are:

field(18; "Upload New Image"; Blob)
        {
            DataClassification = CustomerContent;
            SubType = Bitmap;
            Caption = 'Upload New Image';
            trigger OnValidate()
            begin
                ImageToBase64 :=  ? //function to get base64 string of an image
            end;
        }
field(22; ImageToBase64; text[2048])
        {
            DataClassification = ToBeClassified;
            Caption = 'Base64 String';
        }
I want to get base64 string automatically as I'll upload new image. I did research on it but I couldn't find a procedure that will take image type blob field as a parameter and will return base64 type string of that image.  Can anyone please guide me to get base64 string of an image? I'm using BC version 15.  Answers will be highly appreciated.
Thanks for reading.
I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    Try something like this

    local procedure ConvertBLOBToBase64String(var FieldRef: FieldRef): Text

       var

           Base64Convert: Codeunit "Base64 Convert";

           TempBlob: Codeunit "Temp Blob";

           InStream: InStream;

       begin

           TempBlob.FromRecordRef(FieldRef.Record, FieldRef.Number);

           TempBlob.CreateInStream(InStream);

           exit(Base64Convert.ToBase64(InStream));

       end;

    check codeunit 8614

  • M Hussnain Javed Profile Picture
    241 on at

    Hi Josh Anglesea, thanks for replying. 

    In the suggested solution, following line of code will not work in my case.

    TenantMedia.Get(Item.Picture.Item(1));    

    Because Microsoft is using media datatype for field picture. And there is a procedure Item which takes an index as a parameter.

    Whereas, I'm using blob data type in a custom page.

    Well my issue is solved by the following procedure:

    procedure getBase64(): Text
        var
            Base64CU: Codeunit "Base64 Convert";
            DataBase64: Text;
            VarInStream: InStream;
        begin
            Rec.CalcFields("Upload New Image");
            Rec."Upload New Image".CreateInStream(VarInStream);
            DataBase64 := Base64CU.ToBase64(VarInStream);
            exit(DataBase64);
        end;
  • Suggested answer
    JAngle Profile Picture
    137 on at

    This might help: community.dynamics.com/.../how-to-get-picture-from-mediaset-through-standard-apis

    I used it to help with this solution: joshanglesea.wordpress.com/.../

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,513

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 742 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 706 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans