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

Community site session details

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

Convert BLOB to Base64 for use in Web Service

(0) ShareShare
ReportReport
Posted on by 10

Hello, I've been trying, and failing miserably, to convert a BLOB data type to and Base64 text string in order to send it through a web service.

Here's what I tried:

In both cases, I get this error:

pastedimage1679921691099v1.png

I tried to set the length of the string to 2048(max value), and then it tried to assign 39,000 characters. I will appreciate any help I can get.

I'm working in BC14.

I have the same question (0)
  • Suggested answer
    Greg Enns Profile Picture
    1,106 on at
    RE: Convert BLOB to Base64 for use in Web Service

    Did you try using the Base64 conversion functions in Codeunit 10 "Type Helper"?

    There is both ConvertValueFromBase64 and ConvertValueToBase64.

  • Jesse Otu Profile Picture
    10 on at
    RE: Convert BLOB to Base64 for use in Web Service
    [quote user="Nitin Verma"]

    In which line you are facing the issue, also you can avoid showing the message and direct your URL in here.

    [/quote]

    The issue is in the codeunits where the data type conversion is happening.

    This is a link to codeunit 4110 and 4111.

    github.com/.../Base64Convert

    pastedimage1679997675008v1.png

    The error is thrown after the line Base64String := Convert.ToBase64String(InputArray).

    This method uses the dotnet Convert subtype to run the conversion.

    I hope this answers your question. The other linked codeunit uses a different implementation but still throws the exact same error.

  • Suggested answer
    Nitin Verma Profile Picture
    21,605 Moderator on at
    RE: Convert BLOB to Base64 for use in Web Service

    In which line you are facing the issue, also you can avoid showing the message and direct your URL in here.

  • Jesse Otu Profile Picture
    10 on at
    RE: Convert BLOB to Base64 for use in Web Service

    Okay Nitin Verma here you go:

    OnRun()
    GetEmployeeImage3('JR');

    GetEmployeeImage3(EmployeeCode : Code[20]) : Text[2048]
    Employees.GET(EmployeeCode);
    IF NOT Employees.Image.HASVALUE THEN
    EXIT;

    TenantMedia.GET(Employees.Image.MEDIAID);
    TenantMedia.CALCFIELDS(Content);
    IF TenantMedia.Content.HASVALUE THEN BEGIN

    CLEAR(PictureText);
    CLEAR(PictureInStream);
    TenantMedia.Content.CREATEINSTREAM(PictureInStream, (TEXTENCODING::UTF8));
    //PictureText.ADDTEXT(Base64Convert.StreamToBase64String(PictureInStream));
    //PicDataBASE64 := Base64Convert.StreamToBase64String(PictureInStream);
    //PicDataBASE64 := Base64Convert1.ToBase64_6(PictureInStream);
    PictureText.ADDTEXT(Base64Convert1.ToBase64_6(PictureInStream));
    MESSAGE(PicDataBASE64);

    END;

    This is my codeunit where I tried using both resources referenced in my original post.

  • Suggested answer
    Nitin Verma Profile Picture
    21,605 Moderator on at
    RE: Convert BLOB to Base64 for use in Web Service

    is it possible to share the code

  • Jesse Otu Profile Picture
    10 on at
    RE: Convert BLOB to Base64 for use in Web Service

    I'm working in BC 14. I've updated my post accordingly.

  • Suggested answer
    Nitin Verma Profile Picture
    21,605 Moderator on at
    RE: Convert BLOB to Base64 in Dynamics NAV for use in Web Service

    Hi,

    Are you trying to do in NAV or BC?

    Thanks.

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

Responsible AI policies

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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,869 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,484

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,242

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans