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

Announcements

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 send item picture to SOAP web service?

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

I need to create a SOAP web service codeunit that gets an item number and returns the picture that is on that item in Business Central cloud.

(I think there can be more that one picture, but I only want to get the first picture.)

I have made the procedure below on a codeunit, but it doesn't return anything.

What am I doing wrong?

    procedure GetItemImage(itemNo: Code[20]) Result: Text

    var
        Item: Record Item;
        TenantMedia: Record "Tenant Media";
        TempBlob: Codeunit "Temp Blob";
        PictureInStream: InStream;
        PictureOutStream: OutStream;
    begin
        if Item.Get(itemNo) then begin
            if Item.Picture.Count = 0 then begin
                exit('');
            end;

            TenantMedia.Get(Item.Picture.Item(1));
            TenantMedia.CalcFields(Content);
            if TenantMedia.Content.HasValue then begin
                Result := '';
                Clear(PictureInStream);
                TenantMedia.Content.CreateInStream(PictureInStream);
                TempBlob.CreateOutStream(PictureOutStream);
                CopyStream(PictureOutStream, PictureInStream);

                PictureInStream.ReadText(Result);
            end;
        end;
    end;
I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    If you want to return the picture as part of your soap ws response i think you have to start by base64 encoding the picture stream. The is a codeunit called base64 convert that can do that for you.

  • Morten Steengaard Profile Picture
    555 on at

    Hi NorthW,

    Thank you for your reply.

    I have changed my code (made one new line and outcommented another), but it still returns blank.

    if TenantMedia.Content.HasValue then begin

       Result := '';

       Clear(PictureInStream);

       TenantMedia.Content.CreateInStream(PictureInStream);

       TempBlob.CreateOutStream(PictureOutStream);

       CopyStream(PictureOutStream, PictureInStream);

       Result := Base64Convert.ToBase64(PictureInStream);

       //PictureInStream.ReadText(Result);

    end;

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I assume you are 100% sure the item you are trying to export actually got a picture?

    Maybe you can try to add another text to your result so you can see that your WS actually return something at all?

    if Item.Picture.Count = 0 then begin

                   exit('NoPicture');

    Might be one step

  • Morten Steengaard Profile Picture
    555 on at

    Hi NorthW,

    I got the streams mixed up. And it seems like I need to add a "true" to the call to "ToBase64" function. I only need to write this code to get it right:

    if TenantMedia.Content.HasValue then begin

       TenantMedia.Content.CreateInStream(PictureInStream);

       Result := base64cnv.ToBase64(PictureInStream, true);

    end;

    Thank you for your time.

    Best regards,

    Morten

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 572 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 331 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 330 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans