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’.
format:
base64ToBinary([Attachments Content])
note: [Attachments Content] is a dynamic content
when using in a flow, it could look like this:
base64ToBinary(items('Apply_to_each')?['contentBytes'])
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.

thank you for this
When trying the base64ToBinary expression, the flow failed saying a field was null. However, I was successful using the ‘Get Attachment’ function.
Thanks!!!!!
I’ve been struggling a lot with this
Thank you very much Tom!!!!! I was struggling a lot with this issue and the base64ToBinary() function solves everything.
Thank you SO MUCH!! I have been trying to solve this problem for hours with no success until I read this!!
Awesome work thanks so much for this I’ve looked at lots of other posts but this is simple and actually works
Hey I am trying to use the expression but my excel file still has its data all messed up and corrupted.
I had a problem with corrupted attachments when I switched from the Outlook to the SMTP Connector. I used the base64ToBinary() function, but I found that when I saved and reopened the flow, it changed automatically!
base64ToBinary(body(‘Apply_to_each’)) turns into body(‘Apply_to_each’)?[‘$content’] which works just fine. Maybe it helps someone.
Thanks for this suggestion. I spent almost 3-4 hrs on this and then after I got this blob. It worked for me.
Thank you!!!!!
Thanks! I have similar problem when sending OneDrive Excel file via Outlook.
The base64ToBinary does not work for me. But I find an Action similar to “Get Attachment” – “Get File Content by Path”. I used that to obtain the File Content.
Then in my Action “Send an email (V2)”, under “advanced options”, “Attachments-Content”, I entered “File Content” retrieved in Dynamic Content. Then vola! The attachment sent can be opened without problem 🙂
Hello Peter,
thank you for sharing the solution!
Thanks.
looked for this exact solution !
“Add ‘Get attachment’ action” works perfect for me.
Now progress to unzip the file inside 🙂
Excellent! base64ToBinary() did the trick. Thanks for posting this.
I am having issues based on my specific flow, which looks different from yours and I could really use some help. Can I email screenshots to get some assistance?
Hello Tina,
I’d recommend posting to the Power Automate forum if it’s an issue unrelated to the article: https://powerusers.microsoft.com/t5/Microsoft-Power-Automate/ct-p/MPACommunity