When you need to decode a Base64 file, Logic Apps can handle it for you. You can use an expression to perform the decoding step. For example, imagine a Logic App that starts with the When an HTTP request is received trigger and receives a Base64‑encoded PDF.

In this Friday Fact we will use Postman to send that encoded PDF into the Logic App.

Naturally, what first occurs to us is to decode the Base64 content, and to do so, we will use one Compose action and the expression decodeBase64().

The expression:
decodeBase64(string(triggerBody()['body']))
In truth, here lies the problem, because further ahead, you want to send that decoded Base64 file via email, and using the expression decodeBase64() will not work properly.
So, how can we decode the Base64 file into a PDF?
📝 One-Minute Brief
Understand why Azure Logic Apps can decode Base64 content in different ways depending on the payload type, and learn how to correctly handle files and binary data without unexpected results.
We simply need to use another expression instead of the decodeBase64, and that expression is:
- base64ToBinary
But what is so different about these expressions:
- decodeBase64: This function takes a Base64 encoded string as input and decodes it into its original binary form. It’s like taking a coded message and decoding it into its original content. So, if you have a Base64 encoded string, you’d use decodeBase64 to turn it back into its binary representation.
- base64ToBinary: This function is used to convert a Base64 encoded string directly into a binary format. It doesn’t decode the string as decodeBase64 does. Instead, it just converts it into binary without decoding it. Think of it like changing the format of a file without understanding its content.
But there is the concept and the reality of it. We might think that converting that string to Base64 is enough to convert the PDF or any other file, but that is not the case.

If we do it that way, what will happen is that we will have a corrupted file that will not open or be recognized, or a blank PDF without content, for example:


So, what I recommend is to use the base64ToBinary expression.

The expression:
base64ToBinary(triggerBody()['body'])

This way, you will be sure that the content you receive will be correctly decoded into the original content, making this process less prone to errors and making life easier!

And remember, this approach works on all sorts of files, from PDFs to PNGs, JPGs, or Text Documents…
To lazy to read? We’ve got you covered! Check out our video version of this content!
Join us next Friday for another Friday Fact!
Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for Sandro’s son!