Do you need to convert an image to a base64 string in your flow?
When getting images from SharePoint into your flow, they will be in a binary format. However, you might need them in a base64 format.
For example, when adding images into the body of an email with HTML or adding images within a PDF you will need the base 64 representation.
This post will show you how to get an image from SharePoint and then convert it to a base64 string.
Understanding Base64 and Image Conversion
Base64 is an encoding scheme that allows you to represent binary data in an ASCII string format.
It is commonly used for various purposes, such as embedding images in email, data transfer, and as a part of data URIs in web applications.
When working with Power Automate, you might come across situations where you need to convert an image file in binary to a Base64 encoded string.
This can be useful for scenarios like getting images from SharePoint and then sending them in email bodies or storing them in other applications.
Get Image Content from SharePoint
To convert a SharePoint image to base64, you first need to get the image content from SharePoint.
Here is how to use the Get file content with path action to get an image from SharePoint.
- Add the Get file content using path action from the SharePoint connector to your flow.
- Select the Site Address for the SharePoint site where your image is stored.
- Select the image file in the File Path input using the file picker menu.
This will get the image content into your flow from SharePoint.
The above File Content dynamic content will then be available to get the file content.
To get only the content, you will need to modify this expression a bit by adding on the
$content key as seen above.
This is the part you will need to convert to a base64 string.
Convert Image Content to Base64 String with the base64 Function
To convert your image content to a Base64 string, you can use the base64 function.
Once you have retrieved the file content, you can use an expression to convert the image content to a Base64 string.
<content> with the output of the Get file content using path action, which can be accessed using the above expression.
This article has shown the process of converting an image to base64. The base64 function allows you to easily encode your binary image files to base 64 when needed.
The Get file content with path action will obtain the content of an image from SharePoint. This content will be in a binary format and you can apply the base64 function to convert the binary data to a base64-encoded string.
This enables integration with other applications or services that require base64-encoded images.
Have you needed to convert an image to base64? How did you do this? Let me know in the comments!