How to return an image file via custom API pages?

  • How to return an image file via custom API pages?

    Posted by DSC Communities on January 20, 2022 at 4:35 am
    • Mario Rossi

      Member

      January 20, 2022 at 4:35 AM

      In BC onprem i am trying to return an image inside a page of type API
      Found this article but it’s quite old and doesn’t work for me, the result is always an empty string

      Qr is a field of type mediaSet inside of table Item
      This is the code that i tried:

      codeunit xxxxx Helper
      {
      Ā  Ā  procedure GetItemPictureJSON(ItemNo: Text): Text
      Ā  Ā  var
      Ā  Ā  Ā  Ā  Item: Record Item;
      Ā  Ā  Ā  Ā  TenantMedia: Record "Tenant Media";
      Ā  Ā  Ā  Ā  PictureText: Text;
      Ā  Ā  Ā  Ā  PictureInStream: InStream;
      Ā  Ā  Ā  Ā  JObject: JsonObject;
      Ā  Ā  Ā  Ā  JToken: JsonToken;
      Ā  Ā  Ā  Ā  TempBlob: Codeunit "Temp Blob";
      Ā  Ā  Ā  Ā  PictureOutStream: OutStream;
      Ā  Ā  Ā  Ā  Converter: codeunit "Base64 Convert";
      Ā  Ā  begin

      Ā  Ā  Ā  Ā  Item.Get(ItemNo);

      Ā  Ā  Ā  Ā  if item.Qr.Count = 0 then begin
      Ā  Ā  Ā  Ā  Ā  Ā  exit('');
      Ā  Ā  Ā  Ā  end;

      Ā  Ā  Ā  Ā  TenantMedia.Get(Item.Qr.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);
      Ā  Ā  Ā  Ā  Ā  Ā  PictureText := Converter.ToBase64(PictureInStream);
      Ā  Ā  Ā  Ā  Ā  Ā  JObject.Add('picture', PictureText);
      Ā  Ā  Ā  Ā  Ā  Ā  JObject.SelectToken('picture', JToken);
      Ā  Ā  Ā  Ā  end;

      Ā  Ā  Ā  Ā  exit(JToken.AsValue().AsText());
      Ā  Ā  end;
      }

      ——————————
      Mario Rossi
      Rossi
      ——————————

    DSC Communities replied 3 years, 8 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘How to return an image file via custom API pages?’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!