Need to send a file through an API or embed an image in an email? You'll need to encode it first. The Power Automate "base64" function converts a string into its base64-encoded version, which is essential when transferring data over systems designed to handle text.
I'm sure you've seen it already because when you use a "Get File Content" action in SharePoint you'll get the information in a base64 format.
Let's see how to use it.
Why use it?
I go into a lot more detail in "Understanding Binary and Base64 in Power Automate", but before you use it, it's important to understand why you would use it in the first place.
It's mainly used in file transfer and to reduce the types of errors that we get with binary files. Binary format includes a lot of special characters that make things a bit harder to transfer over the wire. It's commonly used in communication between systems, where you need to use text formats.
Power Automate uses this extensively behind the scenes, like when getting information from SharePoint, for example. If you allow systems to "talk with each other", the communication needs to be done with a set of rules that make problems like quotes, double quotes and more not happen.
Base64 clears these errors because it uses a very limited set of characters, making things deterministic when we want to transfer text (even if it contains the file) from one system to another.
You'll see external tools that have the "File Contents" field that, commonly, expect this type of data to be provided.
Usage
It follows a simple pattern where we provide the string to encode. For example:
base64('hello')
will return
'aGVsbG8='
We're using a string as an example, but you almost never will use a string. The most common usage for this function is to provide a binary file and then send it to an external entity or API to process.
It's also worth noting that Power Automate automatically performs base64 encoding and decoding behind the scenes in many cases, so you don't always need to do it manually. Also, if you find old examples using "decodeBase64", that function is deprecated. Use "base64ToString" instead.
Edge Cases
Designer rendering bug
If you manually add a "base64" expression in the designer, save, and come back later, the expression may visually disappear from the designer. Don't panic - the flow still works correctly. You can verify by using Peek Code or switching to code view. This is a known behavior documented by Microsoft.
UTF-8 encoding only
The "base64" and "base64ToString" functions assume UTF-8 encoding. If you're working with files encoded in ANSI (Windows-1252) or ISO 8859, special characters like accented letters will be lost when round-tripping through these functions. There's no native workaround for this in Power Automate - you'd need an external service to convert the encoding first.
Limitations
Size overhead
Not a limitation per se, but it's important to know that when you use base64 the encoded result is about 33% larger than the original binary data (original string) because of encoding overhead, making the transfer of files a bit more costly in terms of time to send the information. I explain why this happens in "Understanding Binary and Base64 in Power Automate".
Message size limit
Power Automate has a 100 MB message size limit for data moving between actions. Since file content is base64-encoded in transit, that ~33% overhead means the effective maximum file size you can work with is roughly 70-80 MB. Exceeding this will give you a buffer size error.
Recommendations
Here are some things to keep in mind.
Avoid unnecessary conversions
I see a lot of examples online where people convert files unnecessarily. If you're working with file content (like from SharePoint), just use the content directly. Avoid chaining "base64" and "base64ToBinary" unless you really need to, and to be honest I don't see a good reason for it.
Use for API transfers
When sending files through HTTP requests or APIs, base64 encoding is often required. The receiving system will decode it back automatically, but please keep this in mind because most systems will require it and fail if you don't send the correct format.
Be sure that you're providing a string
Always be sure that you're providing a valid string. If the value is null, you'll get an error. Use the "coalesce" function to handle this:
base64(coalesce(<your value>,''))
Or better yet, don't even call the base64 since it doesn't make sense to call it with an empty string.
Always add a comment
Adding a comment will help others understand your formula. Indicate what the function is doing and why, especially if the expression is complex.
Final Thoughts
The "base64" function is a simple but essential tool when you need to transfer files or binary data between systems. Keep it in your toolbox for API integrations, and remember that most of the time Power Automate handles the encoding for you behind the scenes.
Sources
Microsoft's base64 Function Reference
Back to the Power Automate Function Reference.
No comments yet
Be the first to share your thoughts on this article!