cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stephenkln
Resolver I
Resolver I

Save Attachments as Sharepoint Files Producing Empty Files

Hey all!

 

I'm having a little trouble. I have a flow set up with two conditions to download and save attachments from a shared mailbox to a sharepoint folder.

 

Capture.PNG

Everything appears to be working...the correct email is pulled...the file is created and saved in the appropriate folder with the correct name. But it's empty...

 

Some of the attachments are PDFs, and some are CSV files. The CSV file that gets saved by the flow has a single cell with "null" in it. The PDF files do not open. Note that it is not an issue with the attachments themselves--they open fine and have data in them--when downloaded manually.

 

Any help would be appreciated!

 

Thanks.

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hello @stephenkln ,

I think the simplest solution in such cases is to store the dynamic content into a 'Compose' action and then use the output from the 'Compose' in the expression.

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

@Anonymous I found a solution that worked for me here: https://powerusers.microsoft.com/t5/I-Found-A-Bug/Email-as-an-attachement-contentBytes-is-null-bug/td-p/53524

 

Under the advanced settings of the initial trigger..."When a new email arrives..."  change the following settings to "Yes"

 

- Only with Attachments

- Include Attachments

 

Note you might have to recreate your flow to get this to work. Simply toggling them to "Yes" did not fix it for me. I had to rebuild the flow from scratch with them toggled "Yes", then my attachments started saving with all the content.

View solution in original post

7 REPLIES 7
tom_riha
Super User
Super User

Hello @stephenkln ,

try to convert the 'Attachments Content' to binary using the base64ToBinary(...) expression. The attachments from an email seem to have a different encoding than expected by SharePoint.

base64ToBinary([Attachments Content])

image.png

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

@tom_riha thanks for the suggestion! I cannot get that to work. [Attachments Content] is not a dynamic content option for the expression. Any other ideas or am I not doing it right?

Hello @stephenkln ,

I think the simplest solution in such cases is to store the dynamic content into a 'Compose' action and then use the output from the 'Compose' in the expression.

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Anonymous
Not applicable

I am having a simmilar problem and I tried to use your solution. but It dident help me.

When I try your solution the flow fails and says the base64ToBinary was expecting a string but got a NULL.

 

I am trying to save attached files from a e-mail sent to a shared email account in a sharepoint folder.

 

PeFo_0-1611060996750.png

 

PeFo_1-1611061079438.png

 

In the Function "Vedhæftede filer" is: triggerOutputs()?['body/attachments']

PeFo_2-1611061303346.png

In Filnavn is used: items('Anvend_på_hver')?['name']

In Filindhold is used: items('Anvend_på_hver')?['contentBytes']

 

The flow runs fine and the files is saved to sharepoint. but the files saved is just max 4 byte large.

even if the originally PDF file is 190 bytes and You cant open the file.

 

 

 

 

Hello @Anonymous ,

the error message tells you that the dynamic content you used in the base64ToBinary(...) is empty, I'd review what is used as the parameter and if it contains any value (store it into a Compose action before the base64ToBinary(...) expression and check if it's not empty).



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

@Anonymous I found a solution that worked for me here: https://powerusers.microsoft.com/t5/I-Found-A-Bug/Email-as-an-attachement-contentBytes-is-null-bug/td-p/53524

 

Under the advanced settings of the initial trigger..."When a new email arrives..."  change the following settings to "Yes"

 

- Only with Attachments

- Include Attachments

 

Note you might have to recreate your flow to get this to work. Simply toggling them to "Yes" did not fix it for me. I had to rebuild the flow from scratch with them toggled "Yes", then my attachments started saving with all the content.

This worked for me.  Thanks!

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (3,835)