How to Convert Base64 to an Image File in Power Automate

To convert base64 to an image file in Power Automate, pass the base64 string through the base64ToBinary() expression and use the result as the File Content of a SharePoint or OneDrive Create file action. If the string starts with data:image/png;base64,, use dataUriToBinary() instead.

A typical case: an API returns Contoso product photos as long base64 strings, and the files your flow saves open as broken images. In this tutorial, I’ll build the working flow step by step, show which function fits which kind of input, and explain the double-conversion mistake that corrupts files.

Quick answer: Add a Create file action, give the file name an image extension such as .png, and set File Content to base64ToBinary(outputs('Base64_string')). Use dataUriToBinary() when the text begins with data:image/...;base64,. Don’t convert content from Get file content: it’s already binary.

Which function should you use?

Power Automate stores file content as binary, and it shows that binary in run history as base64 text. That’s why it’s easy to convert something twice. Check what you actually have before picking a function:

What you haveExampleWhat to use
A plain base64 stringiVBORw0KGgoAAAANSUhEUg...base64ToBinary()
A data URIdata:image/png;base64,iVBORw0...dataUriToBinary()
Output of Get file content (SharePoint or OneDrive)Run history shows $content-type and $contentNothing: pass it straight to the next action
A file, and you need base64 textTo embed an image in HTML or send it to an APIbase64() or ?['$content']

A plain base64 string usually comes from an HTTP response, a Dataverse image column or a JSON field. I keep it in a Compose action in Power Automate so the expression stays short and easy to test.

Convert a base64 string to an image file

My test flow is an instant flow with three steps: Manually trigger a flow, a Compose action renamed Base64 string, and the SharePoint Create file action. The Compose action holds the base64 text of a small Contoso logo in PNG format.

Step 1: Store the base64 string

Add a Compose action and paste the base64 text into Inputs. In a real flow, this is where you’d put the dynamic content from the API or the column that returns the string.

Paste long strings rather than typing them. In the new designer, typing a forward slash (/) opens the dynamic content menu, and base64 text is full of slashes.

Step 2: Create the file with base64ToBinary()

Add the SharePoint Create file action and fill it in:

  • Site Address: your site.
  • Folder Path: Shared Documents (or any library folder).
  • File Name: contoso-logo.png. The extension tells SharePoint how to open the file, so it must match the real image type.
  • File Content: select the fx button and enter the expression below.
base64ToBinary(outputs('Base64_string'))
Power Automate SharePoint Create file action with File Name contoso-logo.png and File Content set to a base64ToBinary expression

If the expression editor reports a problem, insert the Compose output from the Dynamic content tab between the brackets instead of typing the action name. Spaces in action names become underscores, so Base64 string is Base64_string.

Step 3: Test the flow and open the file

Save the flow, select Test > Manually, and run it. All three steps should show a green check.

Power Automate run results showing Manually trigger a flow, Base64 string and Create file all completed successfully

Open the library and select the new file. SharePoint previews it as a normal image, which proves the bytes were decoded correctly. To move files like this between libraries later, see how to save SharePoint list attachments to a library.

SharePoint preview of contoso-logo.png, the PNG image Power Automate created from a base64 string

When the string starts with data:image (dataUriToBinary)

Power Apps camera, pen input and image controls usually send a data URI to a flow, such as data:image/png;base64,iVBOR.... That prefix isn’t base64, so base64ToBinary() produces a broken file. Use the function made for it:

dataUriToBinary(triggerBody()?['text'])

If you only have base64ToBinary() in an existing flow, strip the prefix first:

base64ToBinary(last(split(triggerBody()?['text'], ',')))

The same binary output works anywhere a file is expected. For example, you can add attachments to SharePoint list items with the SharePoint Add attachment action, whose File Content field also takes binary.

Example: save a Microsoft Forms image upload to SharePoint

A common case is a form with a file upload question. My Equipment Allocation form asks for an equipment photo, and the flow attaches it to a SharePoint list item. Here’s the important part: this flow needs no base64 conversion at all.

Start with the Microsoft Forms trigger When a new response is submitted and select the form.

Power Automate When a new response is submitted trigger with the Equipment Allocation form selected

Add Get response details with the same form and the Response Id from the trigger.

Power Automate Get response details action with Form Id Equipment Allocation and the Response Id dynamic content

The upload answer arrives as JSON text that describes the file, including its name. Add Parse JSON, set Content to the upload question, and generate the schema from a sample run.

Power Automate Parse JSON action with the Equipment Image upload answer as Content and a file array schema

For forms you own, uploads are saved in your OneDrive under /Apps/Microsoft Forms/<form name>/<question>/. Add Get file content using path and build the path from the file name. Power Automate wraps it in a For each loop, which handles several uploads.

Power Automate Get file content using path action with a Microsoft Forms OneDrive path and the file name expression

Now add the SharePoint Add attachment action and set File Content to the File content output of the previous step. It’s already binary, so wrapping it in base64ToBinary() isn’t needed. If you’re new to this trigger, see how to save Microsoft Forms responses to a SharePoint list.

Convert an image to base64 (the other direction)

Sometimes you need the text instead of the file, for example to embed a picture in an HTML email or send it to an API. After Get file content, use either expression:

base64(body('Get_file_content'))
body('Get_file_content')?['$content']

To show the image inside an email body, build a data URI such as data:image/png;base64, followed by that text in an <img> tag. I cover the details in embed an image in an email.

Can Power Automate change an image format, such as PNG to JPG?

Not with built-in actions. base64ToBinary() only decodes the bytes; it never changes the format. Renaming logo.png to logo.jpg doesn’t convert anything either, and some apps then refuse to open the file.

The OneDrive for Business Convert file action converts supported documents to PDF, not to other image formats. For PNG, JPG or WebP conversion you’ll need a third-party connector or your own Azure Function. If PDF is what you’re after, see how to convert Word files to PDF without a premium connector.

Troubleshooting

  • The image opens as broken or corrupt: you converted content that was already binary, or you passed a data URI to base64ToBinary(). Check the input in run history and use the table above.
  • The expression disappears after you edit the action: Microsoft notes the designer can hide these conversion functions. Check the action in Code view.
  • The flow fails with a long pasted string: expressions are limited to 8,192 characters. Keep big strings in a Compose action or dynamic content, not inside the expression.
  • Large files fail: a single message in a cloud flow can’t exceed 100 MB, and base64 text is about a third larger than the file.
  • The file opens in the wrong app: the extension doesn’t match the real type. A PNG string needs a .png name.

These Power Automate file tutorials pair well with this one:

Frequently Asked Questions

What does base64ToBinary() do in Power Automate?

It turns a base64-encoded string into binary file content that actions such as Create file and Add attachment accept. See the base64ToBinary reference on Microsoft Learn for the syntax.

What’s the difference between base64ToBinary() and dataUriToBinary()?

base64ToBinary() expects plain base64 text. dataUriToBinary() expects a full data URI that starts with data:image/png;base64, as Power Apps image controls send.

Why is my converted image corrupt?

Usually the content was already binary, such as the output of Get file content, and it was converted again. Pass that output straight to the next action.

How do I get the base64 text of an image file?

After Get file content, use base64(body(‘Get_file_content’)) or read the $content property of the output.

Can Power Automate convert a PNG to a JPG?

Not with built-in actions. base64ToBinary() only decodes bytes, so you’d need a third-party connector or an Azure Function to change the format.

2 thoughts on “How to Convert Base64 to an Image File in Power Automate”

  1. You mentioned “Get the JSON code from the above step” however there is not a code can you also write that code as well to help the beginners.

Comments are closed.