You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Web Services导出Business Central商品图片且不增大体积?

如何无体积膨胀导出Business Central商品图片?

问题背景

需要从外部应用获取Business Central的商品图片,计划按官方建议使用Web Service方式,但遇到一系列问题。

尝试的操作及问题

  1. 调用官方OData图片端点失败
    请求地址:

    https://api.businesscentral.dynamics.com/v2.0/de2fx7xx-a7e0-4fb8-8f39-215792c9xx53/Sandbox_PL/ODataV4/Company('Prueba%20Global%2C%20S.L.U.')/items('PL006001')/picture
    

    返回错误:

    {
        "error": {
            "code": "BadRequest_NotFound",
            "message": "The URI segment 'picture' is invalid after the segment 'items('PL006001')'."
        }
    }
    
  2. 验证默认items端点不可用
    执行请求:

    https://api.businesscentral.dynamics.com/v2.0/de2fx7xx-a7e0-4fb8-8f39-215792c9xx53/Sandbox_PL/ODataV4/Company('Prueba%20Global%2C%20S.L.U.')/items
    

    响应为 404 Not found,确认默认的Items Web服务未启用。

  3. 自定义页面Web服务无图片数据
    创建了指向Item表的自定义页面Web服务:

    page 60011 "MAG Item Image API"
    {
        ApplicationArea = All;
        Caption = 'Item Image API';
        PageType = List;
        SourceTable = Item;
        UsageCategory = Administration;
    
        layout
        {
            area(content)
            {
                repeater(General)
                {
                    field(ItemNo; Rec."No.")
                    {
                        ApplicationArea = All;
                        ToolTip = 'Specifies the number of the item.';
                    }                
                    field(Picture; Rec.Picture)
                    {
                        Caption = 'Picture';
                        ApplicationArea = All;
                        ToolTip = 'Representation of the first picture.';
                    }
                }
            }
        }
    }
    

    但返回响应中仅包含商品编号,无图片数据:

    "value": [
            {
                "@odata.etag": "W/\"JzE5OzE4NjEzODI5Mjk5MDMxNTIyNDIxOzAwOyc=\"",
                "ItemNo": "PL006001"
            }
        ]
    
  4. Base64转换方案存在体积问题
    编写了将图片转为Base64的函数,可正常运行但会导致图片体积增大,无法接受:

    procedure ConvertMediaSetToBase64(): Text
    var
        TenantMedia: Record "Tenant Media";
        Base64Convert: codeunit "Base64 Convert";
        InStream: InStream;
    begin
        if Rec.Picture.Count() = 0 then
            exit('')
        else
            if TenantMedia.Get(Rec.Picture.Item(1)) then begin
                TenantMedia.CalcFields(Content);
                if TenantMedia.Content.HasValue() then begin
                    TenantMedia.Content.CreateInStream(InStream, TextEncoding::Windows);
                    exit(Base64Convert.ToBase64(InStream));
                end;
            end;
        
        exit('');
    end;
    

提问

如何在不增大图片体积的前提下导出Business Central中的商品图片?


内容的提问来源于stack exchange,提问作者kuhi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 23:47:49