cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chloelawr
Regular Visitor

Multiple attachments array is corrupting image file

Hi everyone,

 

I am trying to create a flow with an array of an attachments and I have followed some of the other articles on here to get help however none of them seem to be resolving my issue.

 

In the flow, I get the attachments from my original email, and then reattach a few of these to another email later in the flow.

 

When I test using the attachments section of the 'Send an email v2', this sends my image file with no issues and I can open it on the other end (seen below)

 

chloelawr_0-1606470600237.png

 

However when I use the same code to append my image to an array variable, my image file is corrupt on the other end and looks something like this:

chloelawr_1-1606470733637.png

 

I have added images of the full flow below. I would really appreciate if someone can identify where I'm going wrong! 🙂 Thank you 

 

chloelawr_2-1606470824022.png

chloelawr_3-1606470840442.png

chloelawr_4-1606470861314.png

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

@chloelawr  @Expiscornovus 

You shouldn't to wrap in base64() as the 'Content Bytes' property in the array should accept a full file contents schema... the base64() expression would just write in the $content value... which can cause issues in arrays.

@chloelawr - if you are trying to add the output from the Encodian action to the array then you need to wrap the Encodian 'File Contents' property in the base64ToBinrary() expression when writing the value into the array variable...

I know this seems odd as the Encodian 'File Contents' is already just as a Base64 string... but, Power Automate will silently re-encode the base64 value and thus you'll get a corrupt output. By wrapping in the base64ToBinary() you are informing PA that this is a file and do not re-encode.

Check out this video which explains this in detail: Add multiple attachments to an email in Power Automate

HTH

Jay

View solution in original post

chloelawr
Regular Visitor

@Expiscornovus thanks but sadly this didn't work and I got the same issue.. although it was close 🙂 

 

@Jay-Encodian it isn't actually the encodian image I am trying to attach, I am just using the encodian image resizer so my AI Logo detector model actually works as the file size was too small before.
However, I used base64tobinary as you advised with the dynamic content I needed and this has worked! Thanks very much 

View solution in original post

7 REPLIES 7
Expiscornovus
Super User
Super User

Hi @chloelawr,

 

Can you try and apply the base64 function to your ContentBytes when appending it in your array variable?

https://sergeluca.wordpress.com/2019/08/15/dynamically-create-a-list-of-e-mail-attachments-with-micr...

 

Let me know if that works.

 

With kind regards,

Dennis

@chloelawr  @Expiscornovus 

You shouldn't to wrap in base64() as the 'Content Bytes' property in the array should accept a full file contents schema... the base64() expression would just write in the $content value... which can cause issues in arrays.

@chloelawr - if you are trying to add the output from the Encodian action to the array then you need to wrap the Encodian 'File Contents' property in the base64ToBinrary() expression when writing the value into the array variable...

I know this seems odd as the Encodian 'File Contents' is already just as a Base64 string... but, Power Automate will silently re-encode the base64 value and thus you'll get a corrupt output. By wrapping in the base64ToBinary() you are informing PA that this is a file and do not re-encode.

Check out this video which explains this in detail: Add multiple attachments to an email in Power Automate

HTH

Jay

chloelawr
Regular Visitor

@Expiscornovus thanks but sadly this didn't work and I got the same issue.. although it was close 🙂 

 

@Jay-Encodian it isn't actually the encodian image I am trying to attach, I am just using the encodian image resizer so my AI Logo detector model actually works as the file size was too small before.
However, I used base64tobinary as you advised with the dynamic content I needed and this has worked! Thanks very much 

Hi @chloelawr Good news 🙂

Basically, if the value you are writing into the array variable is just a base64 string then it needs to be wrapped in the base64ToBinary() expression otherwise PA will silently re-encode the base64() again! The difficulty is you can't see this change in the run history.

Thanks @Jay-Encodian.. understood! I was trying with so many different scenarios so I'm glad I gave up in the end and came to ask the community.. I would have never got it otherwise 😀

Expiscornovus
Super User
Super User

Thanks @Jay-Encodian, I wasn't aware it silently re-encodes it and you have to use the base64ToBinary() expression. Good to know 🙂

Anonymous
Not applicable

@Jay3 

This corrupted file issue is exactly the one that I am having, but instead of an image file, I am mostly using excel files. I went and watched the blog video that you mentioned in your post, and while I was able to faithfully reproduce the error in a test flow, when I try to input the expression base64ToBinary(outputs('get_file_content')?['body']), I get an error saying that the function expected a data type of 'string' but instead had the input 'Object'.

When I change the expression to base64(outputs('Get_file_content')?['body']), the 'ContentBytes' appears to be in binary, but the email attachment is still corrupted. 

I have been looking to see if there was a way to convert the input body('Get_file_content') into a string from an object but have not found anything promising. Any advice on how to proceed with the base64ToBinary solution would be much appreciated!

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,129)