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

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
    Inge M. Bruvik Profile Picture
    1,041 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.

  • 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,041 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,

    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,237

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,425

#3
Sumit Singh Profile Picture

Sumit Singh 2,907

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans