We provide a number of actions which operate on an array of documents such as merging and adding to a ZIP file.
As per the articles on our support site and on this blog; to perform an action on a collection of documents you need to build an array of documents in JSON format, for example:
NOTE: We have highlighted the following expression inside the ‘Append to array variable‘ action: base64(body(‘Get_file_content_using_path’))
What is this expression doing?
Let’s start by explaining the schema of the ‘File Content‘ parameter provided by most Microsoft actions used to ‘Get a file’.
The Microsoft ‘File Content‘ parameter contains two properties:
- $content-type = Media Type (also known as a MIME type)
- $content = Base64 string (The actual file)
Most actions / API’s (like Encodian’s) are expecting to receive a file as a Base64 string, so the following expression is ensuring that only the $content property is added to the array and not the complete value of the ‘File Content‘ parameter: base64(body(‘Get_file_content_using_path’))
But processing the array fails…
Power Automate has some very clever post-processing capabilities which attempt to ensure that the correct data (Base64) is sent when required… however, sometimes this just doesn’t work as expected.
We have crafted two almost identical Flows, the only difference is that one trigger action is different from the other Flow. One Flow works and the other (triggered from SharePoint) fails with the following error:
So the Encodian action doesn’t work! Well, not quite… The Encodian action is actually receiving bad data from Power Automate!
This is the input to the failed Flow action:
The data is correctly formatted and is the same as the data sent to the working merge action (below)!
There are however obvious differences in these two payloads; the first failing action’s properties contain the following prefixes ‘operation/<value>‘:
This indicates that Power Automate is going to do some post-processing on the data before it is sent to the target endpoint, the Encodian action in this instance. In these scenarios the post-processing assumes that the ‘fileContent’ property is the full ‘File Content’and processes it as such… this basically corrupts the Base64 string sent to the endpoint!!! which is why the action fails.
How do I fix it?
The fix is pretty simple, rather than use the base64() expression, simply pass the full ‘File Contents‘ property (the example shows an attachment):
The data is now formatted to contain the complete ‘File Content’s property and Power Automate’s post-processing engine will ensure only the $content (Base64 string) is sent to the endpoint:
The previously broken flow is now working!
NOTE: If we apply the same change to the other Flow which still uses the expression Base64() expression it will fail as Power Automate does not always perform this post-processing.
We are working with Microsoft to determine when this post-processing will happen and when it will not happen and whether there is a more consistent solution that will work in all scenarios. Together, we haven’t yet been able to define this… once we have we will update the document and guidance.
For now, this hopefully helps to resolve your issue, if you still require help please email firstname.lastname@example.org