Friday 10 May 2024

How to Convert Images to Base64 Strings in D365 Finance & Operations

In this blog, I will discuss how to convert an image into a base64 encoded string in Dynamics 365 Finance and Operations (D365FO). Fortunately, D365FO provides a built-in class, BinData, equipped with a method that returns a base64 encoded string. Below, I have provided a block of code that demonstrates how to accomplish this task.

Explanation of the Source Code:

  1. Initialize and Declare the BinData Class: First, create an instance of the BinData class, which will be used to handle the binary data of the image.

  2. Retrieve the Image from a Worker: Obtain the image file associated with a worker. This image is typically stored as a binary file or blob in the database.
  3. Pass the Image to setData() Method: Load the image data into the BinData instance using the setData() method. This method prepares the image data for conversion by handling it as binary data.

  4. Convert to Base64 Encoded String: Use the base64Encode() method of the BinData class to convert the binary data of the image into a base64 encoded string. This string can then be used in HTML, stored, or transmitted as needed.

That is it. Thanks.

No comments:

Post a Comment

How to Get Customer Free Text Invoice "Totals" form field value with X++ in D365FO

Customer free text invoices are an essential aspect of financial management in D365FO. In this blog, I have compiled all the code needed to ...