How to avoid corrupt email attachment in Power Automate
Posted On August 30, 2020
Are you working on a Power Automate flow to download/upload attachment from an email, but the attachment is corrupt?
Corrupt attachment from an email is one of the most common problems in Power Automate. It doesn’t matter if you need to download the files, upload them somewhere else, attach them to a task or another email. There’s a chance you saw error message as below. So how to avoid it?
Add base64ToBinary() expression
The expression base64ToBinary() should help. If you get an error there’s a chance that the file content is not properly encoded. Use the base64ToBinary() expression to convert the ‘Attachments Content’.
note: [Attachments Content] is a dynamic content
when using in a flow, it could look like this:
Instead of using the ‘Attachments content’ directly.
Use the base64ToBinary expression.
I’ve never had this issue with files located in SharePoint or OneDrive, the only problematic source seems to be the email attachments. And even there I didn’t understand why it sometimes works and sometimes not. But using the expression above when processing email attachments seems to solve the corruption problem.
Add ‘Get attachment’ action
Another option to try if the expression doesn’t work is to add ‘Get attachment’ action before processing the file. Instead of using the attachments data from the trigger, include an extra step in your flow to load the attachment data.
This was a workaround I originally used when testing a flow. The problem was that the file was created properly when I actually sent an email, but when I tried to test-run the flow, the files were corrupt. But since then I found the expression above that seems to work much better than this.