Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

How to avoid corrupt email attachment in Power Automate

Posted on August 30, 2020April 10, 2022 by Tom

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.

corrupt attachment power automate

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.

corrupt attachment power automate

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

16 thoughts on “How to avoid corrupt email attachment in Power Automate”

  1. omar says:
    April 13, 2021 at 12:12 am

    thank you for this

    Reply
  2. David says:
    April 29, 2021 at 2:19 am

    When trying the base64ToBinary expression, the flow failed saying a field was null. However, I was successful using the ‘Get Attachment’ function.

    Reply
  3. Isaac says:
    June 22, 2021 at 3:27 pm

    Thanks!!!!!
    I’ve been struggling a lot with this

    Reply
  4. Pancho says:
    July 3, 2021 at 1:50 am

    Thank you very much Tom!!!!! I was struggling a lot with this issue and the base64ToBinary() function solves everything.

    Reply
  5. Rolando says:
    July 7, 2021 at 6:45 am

    Thank you SO MUCH!! I have been trying to solve this problem for hours with no success until I read this!!

    Reply
  6. Paul says:
    July 13, 2021 at 12:49 am

    Awesome work thanks so much for this I’ve looked at lots of other posts but this is simple and actually works

    Reply
  7. Pulakit Mishra says:
    August 20, 2021 at 9:46 pm

    Hey I am trying to use the expression but my excel file still has its data all messed up and corrupted.

    Reply
  8. Ingo D. says:
    August 28, 2021 at 8:08 am

    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.

    Reply
  9. Vijay P says:
    December 13, 2021 at 3:12 pm

    Thanks for this suggestion. I spent almost 3-4 hrs on this and then after I got this blob. It worked for me.

    Reply
  10. Gablic says:
    January 28, 2022 at 9:44 am

    Thank you!!!!!

    Reply
  11. Peter Lau says:
    March 1, 2022 at 11:26 pm

    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 🙂

    Reply
    1. Tom says:
      March 5, 2022 at 7:16 pm

      Hello Peter,
      thank you for sharing the solution!

      Reply
  12. Yehuda says:
    March 8, 2022 at 12:04 pm

    Thanks.
    looked for this exact solution !
    “Add ‘Get attachment’ action” works perfect for me.
    Now progress to unzip the file inside 🙂

    Reply
  13. JP says:
    June 5, 2022 at 6:56 pm

    Excellent! base64ToBinary() did the trick. Thanks for posting this.

    Reply
  14. Tina Lamkey says:
    June 22, 2022 at 3:43 am

    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?

    Reply
    1. Tom says:
      June 28, 2022 at 4:23 pm

      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

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Now available:

The Ultimate Power Automate expressions cheat sheet
Equip yourself with the tool to translate your thoughts into Power Automate expressions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Format results of date calculation in SharePoint columnJune 29, 2022
  • Why is your Power Automate flow creating duplicatesJune 26, 2022
  • How to create a unique identifier in your Power Automate flowJune 22, 2022
  • How to assign custom SharePoint permission level with Power AutomateJune 19, 2022
  • Remove permissions from a specific SharePoint user with Power AutomateJune 15, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme