Site name
How to convert a data URI (Base64) into an email attachment using Power Automate cover image

How to convert a data URI (Base64) into an email attachment using Power Automate

9/12/2025 · 3 min read


Have you ever tried to send an image from a PowerApp or another service as an email attachment in Power Automate, only to find it doesn't work?

A common issue is that the image data comes as a data URI (Data Uniform Resource Identifier), which often includes extra characters like quotes and backslashes that break the attachment.

A Data URI is a scheme for including data in-line, meaning the data for a file (like an image) is embedded directly into the text string itself. This is often done to avoid making a separate request to fetch a file. The problem in Power Automate arises because this data string often includes extra characters like quotes and backslashes that can break the attachment process.

The problem would look like this in the trigger body: "text_4": "\"data:image/png;base64,AAA...\""

Those escaped quotes (\") are what cause the trouble. Luckily, there's a straightforward way to fix it. We'll use a series of Compose actions to clean the data and convert it into a usable binary format. This post will show you two different paths, depending on whether your data has those pesky quotes and backslashes or not.

Path A — For values with quotes and backslashes

If your data is wrapped in quotes and includes backslashes, you'll need to clean it up first. We'll do this in four steps using Compose actions.

  1. Raw First, get the raw data from the trigger body. triggerBody()?['text_4']
  2. Clean This is the crucial step where we remove the extra characters. We'll use the replace and trim functions to get rid of the backslashes and quotes. trim(replace(replace(outputs('Raw'), '\', ''), '"', '')) This should return something clean like data:image/png;base64,AAA...
  3. Base64_only Now, we need to isolate the Base64 string itself. The split function separates the string at the base64, marker, and last grabs the final part, which is the pure Base64 data. last(split(outputs('Clean'), 'base64,'))
  4. Binary Finally, we convert the Base64 string into a binary format that Power Automate can use for an attachment. base64ToBinary(outputs('Base64_only'))

Power Automate will look something like this: Path A

And the results will look like this: Path A - Run Results

Path B — For values that are already clean

If your data doesn't have the escaped quotes and backslashes, you can skip the cleaning step and go straight to isolating the Base64 string.

  1. Raw Get the raw data. triggerBody()?['text_4']
  2. Base64_only Isolate the Base64 string from the data URI. last(split(outputs('Raw'), 'base64,'))
  3. Binary Convert the Base64 string to binary. base64ToBinary(outputs('Base64_only'))

Quick sanity checks

Before sending, it’s a good idea to confirm your Base64_only output looks correct. A Base64-encoded PNG image should:

  1. Start with iVBOR.
  2. End with = or ==.
  3. Have no backslashes, quotes, or whitespace.

You can use this optional expression to check if the string is valid: and(startsWith(outputs('Base64_only'),'iVBOR'), or(endsWith(outputs('Base64_only'),'='), endsWith(outputs('Base64_only'),'==')))

Email wiring (Send an email (V2) action)

Once you have your binary data, configuring the email action is simple.

  1. Attachment Name: Give your file a name, like image.png.
  2. Attachment Content: Pass the output of the Binary Compose action here: outputs('Binary').

Send an email action

💡 Tip: Some connectors might accept the raw Base64 string directly. In that case, you can pass outputs('Base64_only') instead of the binary output.