如何通过Web Services导出Business Central商品图片且不增大体积?
如何无体积膨胀导出Business Central商品图片?
问题背景
需要从外部应用获取Business Central的商品图片,计划按官方建议使用Web Service方式,但遇到一系列问题。
尝试的操作及问题
调用官方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')'." } }验证默认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服务未启用。自定义页面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" } ]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
相关产品推荐
相关产品推荐

