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

Get URL of Item Picture using custom API.

(1) ShareShare
ReportReport
Posted on by 163
Hi All,

I am using On-Prem Business central.

I have created on custom API which is returning the item detail with item picture in base64 string. but it is taking long time to fetch data using API(45 second). Due to the large base64 string it is taking long time to process.

Does anyone have any idea how i can optimize it.

Or anyone have how idea how i can get exact URL of image which i can set in the image tag Source. eg. <img src="itemURL">.

Code : 
page 50119 "GetAllItemsDetail"
{
    PageType = API;
    APIVersion = 'v1.0';
    APIPublisher = 'QueryV1';
    APIGroup = 'QueryGroup';
    EntityName = 'Item';
    EntitySetName = 'Items';
    DelayedInsert = true;
    SourceTable = Item;
    layout
    {
        area(content)
        {
            repeater(Group)
            {
                field(ItemNo; Rec."No.")
                {
                    Caption = 'Item No';
                }
                field(BrandName; Rec."Brand Name")
                {
                    Caption = 'Brand Name';
                }
                field(Base_Unit_Price; Rec."Unit Price")
                {
                    Caption = 'Base Unit Price';
                }
                // Picture content in base64
                field(PictureContent; GetItemPicturesAsJSON(Rec."No."))
                {
                    Caption = 'Picture Content';
                    ApplicationArea = All;
                }
            }
        }
    }
   // Procedure to get base64 string of image.
    procedure GetItemPicturesasJSON(ItemNo: Code[20]): Text;
    var
        Item: Record Item;
        TenantMedia: Record "Tenant Media";
        PictureText: Text;
        PictureInStream: InStream;
        JObject: JsonObject;
        JToken: JsonToken;
        TempBlob: Codeunit "Temp Blob";
        PictureOutstream: OutStream;
        Base64Convert: Codeunit "Base64 Convert";
    begin
        Item.get(ItemNo);
        if Item.Picture.Count = 0 then
            exit('');
        TenantMedia.get(Item.Picture.Item(1));
        TenantMedia.CalcFields(Content);
        if TenantMedia.Content.HasValue then begin
            Clear(PictureText);
            Clear(PictureInStream);
            TenantMedia.Content.CreateInStream(PictureInStream);
            TempBlob.CreateOutStream(PictureOutstream);
            CopyStream(PictureOutstream, PictureInStream);
            TempBlob.CreateInStream(PictureInStream);
            PictureText := Base64Convert.ToBase64(PictureInStream, false);
            JObject.Add('picture', PictureText);
            JObject.SelectToken('picture', JToken);
        end;
        exit(JToken.AsValue.AsText);
    end;
}


Thanks for help.
I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    27,054 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    101,787 Super User 2026 Season 1 on at
    I think you can change the idea, convert it first and save it in blob, and then read it from the blob field via API?
     
    Hope this can give you some hints.
    Thanks.
    ZHU

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 Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,497 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,778 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,507

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans