如何通过Web服务导出Business Central中的图像?

问题描述 投票:0回答:1

我正在尝试从另一个应用程序获取我的 Business Central 产品图像,因此我正在考虑按照文档建议使用 Web 服务 Microsoft Doc

我正在邮递员中运行此请求:

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')'."
    }
}

所以我猜端点不可用?让我们确认另一个请求:

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

如果 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"
        }
    ]

所以,没有图片...我创建了一个以 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;

如何导出图像而不导致图像比原始图像更大?

microsoft-dynamics dynamics-365 dynamics-business-central dynamics-al businesscentral
1个回答
0
投票

Web 服务是一种通过 SOAP 或 OData 协议从 Business Central 公开对象的旧方法。基本上,该平台尝试根据例如以下内容生成有效的 API:页面(这是一个 UI 元素)。这意味着什么是可能的,什么是不可能的,存在一些限制。

我建议您改用新的 API 端点。在这里,您可以使用开箱即用的商品 API 及其图片。

根据您的示例,特定项目图片的端点应如下所示:

https://api.businesscentral.dynamics.com/v2.0/de2fx7xx-a7e0-4fb8-8f39-215792c9xx53/Sandbox_PL/api/v2.0/companies({{Company Id}})/items({{Item Id}})/picture/pictureContent

如果您想获取所有项目的图片,您需要首先获取展开图片属性的项目,然后按照上述方式获取图片:

https://api.businesscentral.dynamics.com/v2.0/de2fx7xx-a7e0-4fb8-8f39-215792c9xx53/Sandbox_PL/api/v2.0/companies({{Company Id}})/items({{Item Id}})?expand=picture
© www.soinside.com 2019 - 2024. All rights reserved.