Like all other Power Automate connectors, the Encodian connector for Microsoft Power Automate (Flowr) and Azure Logic Apps receives and sends files as Base64 encoded strings. This is important to understand when working with files in Power Automate and Logic Apps.
A common misconception is that an action performed by a Power Automate connector (like Encodian) is performed in situ, i.e. the connector accesses a file directly and performs the configured action. This is not the case: you need to configure your Flow to obtain the target file from its storage location, pass this file to a connector for processing, which would then return the processed file… then finally, you would do something with the file, like adding to SharePoint.
Consider this example which shows how to convert a document stored within SharePoint to PDF using the Encodian connector:
A file copy is retrieved from SharePoint and sent to Encodian for processing. The document is leaving the Microsoft 365 tenancy to be processed. This is not specific to Encodian; this is how connectors interoperate within Microsoft Power Automate.
Encodian’s infrastructure is hosted 100% within Microsoft Azure data centres. Your data will never leave a Microsoft data centre. Where required, we can provide a ‘Dedicated Connector‘ where a copy of the Encodian connector is deployed directly into your Azure tenant, therefor data never leaves your Microsoft cloud tenancy.
Exploring Power Automate ‘File Contents’ in detail
Let’s explore the previous example in more detail to understand how the file is processed:
Hopefully, this screenshot depicts the data flow succinctly and exposes some of the clever processing performed by Microsoft behind the scenes.
You’ll notice in the first completed action that the ‘File Content‘ property returned by the SharePoint ‘Get file content‘ action contains more than just a Base64 string:
The ‘File Contents‘ schema explained:
{ "$content-type": "<MIME Type>", "$content": "<Base 64 String>" }
$content-type is a MIME Type (or media type), which helps to describe the document format; $content is the Base 64 string, the actual file encoded.
You may also have noticed that the data sent to the Encodian connector in the example is just the $content value and not the total ‘File Content’ property value:
Microsoft Power Automate is intelligently processing data to ensure that data is sent in the correct format. This is a super important concept, especially when working with documents using different actions.
This processing is also performed on the value returned by the Encodian action, whereby Microsoft Power Automate is automatically transposing the Base64 string into a complete ‘File Contents‘ property.
But why is this important?
For most simple scenarios, this isn’t something you need to consider. Still, when you are processing files received in different ways (HTTP Post, PowerApps) or collating an array of documents for merging, things can go awry… very awry!
The critical consideration is that Power Automate performs pre/post-processing on Base64 strings to ease interoperability. Occasionally, you need to add extra steps to your flow to ensure that files are not corrupted en route. For example, consider this example of building an array of documents:
We’ve already seen that Microsoft dynamically extracts just the $content value… so the ‘Append to array variable‘ should append this:
"file": "<Base 64 String>"
But it doesn’t – see below:
Power Automate is reacting to the destination and, in this instance, has decided that an array variable expects binary data and has tried to append a binary value. Thankfully, we can use expressions to override the default behaviour, and this example shows how the Base64() expression is used to inform Power Automate to provide data in the desired format:
And the resulting output is now correct:
If you are appending files to Power Automate array variables, review the following video as there are some gotcha’s to be aware of!
Finally…
Hopefully this post has provided some additional insight into how Microsoft Power Automate processes files. Should you experience issues, you should always check the run history and validate that data is passed correctly… it’s usually apparent when documents (File contents) are being given in an incorrect format.
We hope you’ve found these quick tips helpful, and as ever, please share any feedback or comments – all are welcome!
9 Comments
Hey,
I was having trouble grabbing file content from Onedrive/teams chat files and was wondering if you can see anything I might be missing.
I define an array variable and with a onedrive ‘get file content’ search add the data:
“file”:”@{body(‘Get_file_content’)}”
My array ends up looking like:
{“name”:”Attachments”,”value”:”\”file\”:\”\”JVBERi0xLjYNJeLjz9MNCjU3IDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MID……
But this seems to break the flow and it never finishes running, any ideas?
Hey, please check out this post: https://blog.encodian.com/2020/04/handling-files-provided-in-a-microsoft-forms-response/
Hi Jay,
How would you handle the use case where the word doc is converted to pdf, but how would we maintain meta data of the file eg columns etc after conversion(similar to copy file action , where document is copied along with metadata, but while converting we create new file file and hence we loose the )
Hi,
The Encodian connector is not directly connected to your Office 365 Tenant.
You would use the SharePoint ‘Create File’ action to add the PDF rendition to SharePoint, and use other SharePoint actions (Get file properties and Update file properties) to copy the metadata values from the source document to the PDF rendition: reference, https://docs.microsoft.com/en-us/connectors/sharepointonline/#actions
HTH
Jay
Hi,
Just Wondering if Encodian is able to compress (Reduce size in MBs) of Multiple Picture Attachments from a SharePoint List enabling MS Flow to Carry Maximum photos along to generate reports?
Thanks
Hi Sohail, Yes, we provide an actions for compressing images: https://support.encodian.com/hc/en-gb/articles/360027350513-Compress-an-Image
You just need to obtain the images from SharePoint using the ‘Get items’ and then the each list item attachment before calling the ‘Compress an Image’ action
Thank you!
You save my day.
I actually implemented reverse operation with the file content. Instead of passing Base64 file content to the FTP Logic App connector, I pass JSON object as file content. And it works!
So, instead of “JVxxxxB==”.
I passed the following one.
{
“$content-type”: “application/pdf”,
“$content”: “JVxxxxB==”
}
Hi there… thanks for this. This video was super helpful as it pertains to single files, but I’m not sure it explained what to do if you are merging documents and using an array to do so? How do you change the output of the array into binary to create the file?
Please review the following post which details how to merge files in Power Automate – Merge Documents to PDF with Power Automate and Encodian