Skip to main content

Notifications

Announcements

No record found.

How to Transfer Files through API using Base64 Stream to Business Central

Introduction:

Transferring data from Business Central Tables through API is one of the latest version of transferring data from or to Business Central using the API Page Objects or  Web Services.
Well, it gets a little difficult to transfer file blobs using the Media.ReadLinks and Media.EditLinks JSON field.


Pre-requisite:
  • Understanding of Business Central API
  • Understanding how Blobs are accessible to Business Central
  • AL Language Extension
  • VS Code
  • Understanding of JSON Data Types
References:

Solution:

1. Using Business Central API to Pass Data from  BLOB to Base64 String:

Whenever you have a file in a BLOB field and want to transfer as a Base 64 string to API - POST Request.

Convert a File(BLOB) To Base64 String



2. Reading the API into Business Central and converting the Base64 String to BLOB:
Whenever there is a call to API and it returns a response to Business Central in the following form

{
        "id":"5678",
        "base64":"T2xpc3Rlcg=="
}

If you realize, you get a JSON Array Object. You need to separate the JSON Array into individual JSON Objects and process each of the File Contents using the FOR LOOP.
In this case, I will simply write the code to just read the values from the array and convert it to a BLOB.
Convert Base64 String to Stream 
Get Token Value from JSON Object
Get Token Value from JSON Object



I shall create a separate blog on explaining the JSON Array Objects and how you can integrate multiple APIs to Business Central using the JSON Array Objects.

Conclusion:
This has been a blog after a long time.
I hope this helps and if you have any suggestions, feedback or have any special requests feel free to write in the comments or email me at olisterr@outlook.com



This was originally posted here.

Comments

*This post is locked for comments