Skip to main content

Notifications

Announcements

No record found.

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;
  • Morten Steengaard Profile Picture
    555 on at
    RE: How to send item picture to SOAP web service?

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: How to send item picture to SOAP web service?

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

    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
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: How to send item picture to SOAP web service?

    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.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans