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

Announcements

No record found.

News and Announcements icon
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
    JAngle Profile Picture
    150 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/.../

  • 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
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 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

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,821 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,122 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans