Reputation: 1
I have a flow in Power Automate that runs on a recurrence trigger. It retrieves multiple .xls files from a folder in OneDrive and sends them via the Outlook application.
The problem I'm facing is that the files are sent but become corrupted when trying to open them. I’ve read that it might be due to the Base64 format. I’ve already tried using the base64ToBinary function, but I haven’t been able to make it work. Either the flow runs, but the files won’t open, or I make changes using the base64ToBinary function, and the flow breaks and won’t save.
I start initializing a variable of type array,enter image description here then I proceed to add the first file using "get file content" de one drive enter image description here. Then I try to append the content to the variable: enter image description here. The code in this step looks like this: enter image description here. Those steps are repeated to get a second file and finally I added the 'sent email V2" action from outlook. enter image description hereThe email is sent but the files are damaged when I try to open them from the attachment. I must clarify that the fils from the original source do work fine. Finally this is the general pictuyre of my flow:enter image description here. please if I must provide further details of the JSON or anything else please let me know, thanks!!
Upvotes: 0
Views: 191
Reputation: 13
I think I found your problem, I got the same problem and I fixed it. I dit following:
{ "Name": "items('foreach_data')?['DisplayName']", "ContentBytes": **body('get_file_content')** }
this is the key, instead of doing this:
{ "Name": "items('foreach_data')?['DisplayName']", "ContentBytes": body('get_file_content')?['$content'] }
you must do this:
{ "Name": "items('foreach_data')?['DisplayName']", "ContentBytes": body('get_file_content') }
because at the end you'll get this in your array:
"emailMessage/Attachments": [
{
"Name": "Mappe.xlsx",
"ContentBytes": {
"$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"$content": "UEsDBBQABgAIAAAAIQA/jEuNawEAABAFAAATAAgCW0NvbnRlbnRfVH..."
}
},
{
"Name": "Mappe1.xlsx",
"ContentBytes": {
"$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"$content": "UEsDBBQABgAIAAAAIQA/jEuNawEAABAFAAATAAgCW0NvbnRlbnRfVH..."
}
}
]
by using this body('get_file_content') you will get this:
{
"$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"$content": "UEsDBBQABgAIAAAAIQA/jEuNawEAABAFAAATAAgCW0NvbnRlbnRfVH..."
}
Upvotes: 0