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

Files Uploaded to OneDrive From SharePoint losing their file content

I have a flow set up that creates a new file in OneDrive using a SharePoint list item's attachments whenever a list item is created or modified. I followed a tutorial online to the letter, but I'm running into an issue.

 

Once uploaded to OneDrive, the file loses its content and format and is essentially useless. It's created in the correct folder with the correct name, but the content itself is gone. I've tried this with PDFs and image files, and the same issue occurs.

 

Below is the layout for my flow.

 

Edit your flow _ Power Automate - Google Chrome 3_1_2022 2_03_35 PM.png

Edit your flow _ Power Automate - Google Chrome 3_1_2022 2_05_14 PM.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
ekarim2020
Super User
Super User

As you save each attachment file to OneDrive add the file extension to the file name:

Snag_9fc3f6.png

The expression to get the file extension is:

 

last(split(item()?['DisplayName'],'.'))

 

And in the File Name, don't for get to add the 'dot' before the file extension:

Snag_a2ff99.png

Each time a list item column is modified, and that list item contains attachments, the flow will create files in OneDrive. I don't know of a way to detect when a list item attachment has been changed such as  attachment added, attachment updated or deleted.


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

I found it difficult to follow your flow. However, take a look at the following example. It should help you in fixing the issue. The flow will save an MS forms file attachment to a SharePoint list item. The flow assumes that the forms file upload is a required field:

Snag_76b212f.png

Note expressions below for json and the Get file metadata:

Snag_7718e24.png

Inputting the json expression:

2022-03-03_19-27-36.gif

Snag_7750624.png

Get the file File extension:

ekarim2020_0-1646334218642.png

 

last(split(outputs('Get_file_metadata')?['body/DisplayName'],'.'))

 

 

Create a SharePoint list item, add the forms file attachment to the item:

Snag_78155ff.png


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

7 REPLIES 7
ekarim2020
Super User
Super User

As you save each attachment file to OneDrive add the file extension to the file name:

Snag_9fc3f6.png

The expression to get the file extension is:

 

last(split(item()?['DisplayName'],'.'))

 

And in the File Name, don't for get to add the 'dot' before the file extension:

Snag_a2ff99.png

Each time a list item column is modified, and that list item contains attachments, the flow will create files in OneDrive. I don't know of a way to detect when a list item attachment has been changed such as  attachment added, attachment updated or deleted.


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

Hi Ellis,

 

Thanks for your solution! Initially, it was working, but as I've moved some elements around, I'm now getting an error in my flow that causes it to fail. The error occurs during the "Compose" action, and I get this message: "InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'split' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#split for usage details.'."

 

Run History _ Power Automate - Google Chrome 3_3_2022 10_14_43 AM.png

 

Any advice?

 

Thanks!

Please share the flow and the expression for the compose action.

 

The split() function is complaining that the string it is trying to split is empty, it does not not contain any data.

 

Ellis

The expression for the compose action is:

last(split(item()?['DisplayName'],'.'))

 

Here's the flow: 

 

JWMartin_0-1646329523106.pngJWMartin_1-1646329560284.png

JWMartin_2-1646329612471.png

JWMartin_3-1646329635892.png

JWMartin_4-1646329674339.png

 

For reference, the "Yes" conditional is almost identical, but with one or two different items that all work fine. The same error occurs with the Compose action in that pathway as well.

 

Basically, the idea of the flow is to take a form entry, log it on a specific SharePoint list based on the type of purchase made, attach a receipt to the list item, then copy that receipt to a specific folder in OneDrive. The email is my failsafe to let the user know that the whole process succeeded. 

 

Originally, I had two separate flows: one for logging the purchase and attaching the receipt, and another for recreating the receipt in OneDrive. The whole process worked, but since it was split between two flows, I felt it was unreliable. I've tried to combine the two flows, basically recreating the 2nd inside the 1st, but now it generates the error.

 

Hope that helps!

I found it difficult to follow your flow. However, take a look at the following example. It should help you in fixing the issue. The flow will save an MS forms file attachment to a SharePoint list item. The flow assumes that the forms file upload is a required field:

Snag_76b212f.png

Note expressions below for json and the Get file metadata:

Snag_7718e24.png

Inputting the json expression:

2022-03-03_19-27-36.gif

Snag_7750624.png

Get the file File extension:

ekarim2020_0-1646334218642.png

 

last(split(outputs('Get_file_metadata')?['body/DisplayName'],'.'))

 

 

Create a SharePoint list item, add the forms file attachment to the item:

Snag_78155ff.png


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

JWMartin
Regular Visitor

Yes, it got it to work! Thanks.

Phil_N
New Member

@JWMartin Wondering if you'd take a look at my question on preserving original file names that are uploaded to OneDrive?

 

https://powerusers.microsoft.com/t5/Building-Flows/Preserve-file-names-that-are-uploaded-to-OneDrive...

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.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (2,625)