Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to avoid corrupt email attachment in Power Automate

Posted on August 30, 2020February 23, 2025 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.

Make sure you’re getting the actual attachment

If the expression tells you that the field is null, make sure that you get the attachments from the email in the first place.

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

🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

53 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
    1. Kirtan says:
      June 26, 2023 at 10:05 am

      same for me

      Reply
      1. Ianna says:
        November 8, 2023 at 4:24 am

        Same for me.

        Reply
        1. TTCU says:
          October 25, 2024 at 2:55 pm

          same here

          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
    1. Detti says:
      February 13, 2024 at 11:09 pm

      You have saved my life with this trick!! thank you I am so grateful 🙂

      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
    1. Sam says:
      April 29, 2024 at 6:20 pm

      This worked for me! Took hours for me to find the issue but this is gold now! Thank you!

      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
  15. Quindan says:
    July 14, 2022 at 12:46 pm

    I spent way too many days on this issue (even leaving the automation completely for two months). Thank you for this amazing post!

    Reply
  16. Syed Shah says:
    July 15, 2022 at 10:14 pm

    I was facing the same issue. I resolved it by selecting “Yes” for includes Attachments in “When a New Email Arrives” trigger.

    Reply
    1. Tyler says:
      October 4, 2022 at 1:52 am

      Thank you so much Syed!! That worked perfectly!! I’ve been beating myself up for 2 days over this.

      Reply
    2. Mike Livingston says:
      March 13, 2024 at 5:12 am

      Syed the select “Yes” made it work for me as well…thanks for posting.

      Reply
    3. Hafiz Asim says:
      December 19, 2024 at 1:47 pm

      Bulls Eye Man

      Reply
  17. bouwmeester says:
    September 2, 2022 at 2:27 pm

    I would like to comment on this.
    For me, it took these two steps to make it function.
    First make sure that “Yes” for includes Attachments in “When a New Email Arrives” trigger.
    Second use Add ‘Get attachment’ action and then “create file”

    This allowed it to work for me.

    Reply
  18. Andrei says:
    October 11, 2022 at 11:54 am

    This worked for me, thanks a lot!

    Reply
  19. Honorata says:
    October 20, 2022 at 4:54 pm

    Thank you so much. Binary solution worked for me 🙂

    Reply
  20. Sara de Hond says:
    October 31, 2022 at 12:43 pm

    Hm, I followed the steps but it is still corrupted. Flow works with no errors. Got the content from a file in sharepoint and on the email attachment added the 64tobinary function and specifying the column to $content as it otherwise is an object.

    Reply
    1. Tom says:
      November 6, 2022 at 8:19 pm

      Hello Sara,
      the solution is from files going from Outlook attachment to SharePoint, no the other way around, files from SharePoint should be fine as they are, no conversion needed.

      Reply
      1. Daiane says:
        November 14, 2022 at 4:17 pm

        That is what my flow does (save an attachment from outlook, if a file with the same exists in the sharepoint folder, it renames the file, then creates the file). I can create the file without a problem if I am not renaming it. Otherwise the result is a corrupted file. The 64tobinary is not working for me.

        Reply
        1. Tom says:
          November 20, 2022 at 6:11 pm

          Hello Daiane,
          if it works when creating but not when renaming then there must be problem somewhere in/after the renaming part, e.g. missing file extension, using wrong dynamic content in one of the actions, etc.

          Reply
        2. Daniel says:
          August 25, 2023 at 12:07 pm

          HI Daiane,
          I know this is quite an old post but, I was also trying to rename a file while creating it in SharePoint. For some reason when used both methods together; 1) Creating a file using 64tobinary then overwriting the same file by 2) Creating a file using Content Bytes this seemed to solve my issue!

          I spent some days troubleshooting this and every other solution I tried wasn’t feasible so I hope this helps!

          Reply
    2. Pieter says:
      January 30, 2023 at 4:35 pm

      Same here Sara. Still struggling to get this fixed.

      Reply
  21. Ethan says:
    February 1, 2023 at 12:22 am

    I am doing the same thing, but instead of SharePoint I am uploading the file to a OneDrive folder. I found that while testing the automation, the file will still give that corrupted error message — but if you get someone to send you a file normally, it seems to work. For OneDrive the code is:

    base64ToBinary(items(‘Create_New_File’)?[‘contentBytes’])

    My process flow is:

    1. When email arrives

    2. Create new file (select attachments as output from previous steps)

    3. Create file OneDrive (this is inside of the create new file step)
    Specify the folder path in OneDrive, the file name (with extension as .xlsx) and put the above code inside the file content section.

    I hope this helps anybody with this same issue.

    Reply
    1. Tom says:
      February 9, 2023 at 9:48 pm

      Hello Ethan,
      tnank you for sharing your solution.

      Reply
  22. Neil says:
    February 6, 2023 at 8:57 pm

    Using the Base64ToBinary option worked like a charm for me. Thank you, I no longer need to pull out my hair…

    Reply
  23. Kira says:
    March 8, 2023 at 10:02 am

    I looked all over the internet today and this is the only thing that helped me. Thank you a million times over!!

    Reply
  24. Kate says:
    May 6, 2023 at 5:39 pm

    I am trying to set up a flow to save a pdf attachment when it is sent to a shared mailbox. I have tried adding both the additional step mentioned above and the base64 code and I’m still having problems.
    The file saves in the correct Sharepoint folder and the flow says it has run correctly, but I can’t open the attachment.
    Any suggestions please?

    Reply
    1. Tom says:
      May 28, 2023 at 2:54 pm

      Hello Kate,
      I’d double check the dynamic contents you use after you get the file / file content and then it’d be mostly trial and error to try the various options one by one.

      Reply
  25. Petr Opletal says:
    May 20, 2023 at 12:13 pm

    It’s absolutely horrible that this isn’t covered anywhere. The only article on powerusers that does not solve anything. I struggled with this for 3 days.
    Infinite thanks.

    Reply
  26. Eric says:
    May 25, 2023 at 5:17 am

    This is great! Thank you for this.
    I tried both methods across several issues and they each work in different situations.

    Reply
  27. Sam says:
    June 14, 2023 at 9:55 am

    Thank you so much!

    Reply
  28. Jennifer says:
    August 23, 2023 at 11:30 pm

    Wow! I’ve been pulling my hair out trying to make this work. 100000000 thank yous!

    Reply
  29. john smith says:
    October 31, 2023 at 9:15 pm

    Thank you, this proved really helpful 🙂

    Reply
  30. Olaf says:
    December 14, 2023 at 9:06 pm

    When I tried to use
    base64ToBinary(items(‘Apply_to_each’)?[‘contentBytes’])
    in the New Designer I received an error (invalid expression).
    When I switched to the Old Designer I could enter ‘File Content’ as Dynamic Content and everything works fine. Looks like Microsoft has some work to do.

    Reply
  31. Finch says:
    January 4, 2024 at 3:50 am

    You just saved me hours of work, thank you!

    Reply
  32. Pingback: Kyocera – Sharepoint – Power Automate – Erhard RAINER
  33. Mark Saffell says:
    January 11, 2024 at 4:15 pm

    Brilliant. The workaround with Get Attachments and using Content Bytes worked perfect! I had a lot of trouble with this. Thanks for posting.

    Reply
  34. AJ799 says:
    February 23, 2024 at 11:00 am

    This post was god send. This just saved me so much time as I was gonna re-design a complex flow to get around this problem.

    Reply
  35. Daniel says:
    December 26, 2024 at 3:44 pm

    tkssssssss <3 you from Brazil

    Reply
  36. Fran says:
    March 4, 2025 at 10:46 am

    Thanks a lot for this! For me adding the “Get attachment V2” did the trick, combined with adding “Yes” in the filters for attachments at the first “On new e-mail” action. We also added a /Reply-to path thing in the destination folder, so that every e-mail with attachments created a new folder on the Onedrive, which was more convenient for our use case. I googled so much for this and wanted an easy fix without too much fiddling. Thank you again!

    Reply

Leave a Reply Cancel reply

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

🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundle—everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes