cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Sharepoint: Add Attachments to List Corrupting FIles

Hi All,

 

Im hoping that someone can help me with this issue.

Basically I have a form setup on Cognito forms that allows the user to upload some files.

When they submit it Flow pick this up and as a new record to a Sharepoint list - This is all working fine.

 

What I am tying to do is for the Attachments to also attach to that record.

 

Here what ive got so far:

 

 The Apply to Each loops through however many files there are and adds each one:

Screen Shot 2017-10-06 at 1.33.23 pm copy.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The images successfully add to the attachments:

Screen Shot 2017-10-06 at 1.34.01 pm.png

 

 

 

 

 

But when any attachment is clicked on I get this error that the file is corrupted:Screen Shot 2017-10-06 at 1.34.17 pm copy.png

 

 

 

This happens no matter what the file type is - Ive tried with PNG, PDF, XLS etc

I feel like I am so close at getting this finished haha!

Any help would be greatly appreiciated.

 

Thanks in advance!

9 REPLIES 9
Highlighted
Community Support
Community Support

Re: Sharepoint: Add Attachments to List Corrupting FIles

Hi AnthonyJackson,

 

I assume that your flow might be configured likes below.


I assume that you should have a File upload field in the form. In my case, I named the File upload field as “YourFile”. However, it seems that in the Add attachment action, I cannot get “YourFile” from the dynamic content. So I use a Compose action to get “YourFile” first then use its Output in the File content field.

3.PNG


The flow runs succeed. However, when I open the attachment in the list, seems that I got the same error message with you.

 

I will help confirm with this issue on my side and back to you later.

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Anonymous
Not applicable

Re: Sharepoint: Add Attachments to List Corrupting FIles

Thats great thank you!

 

Yeah Ive tried it a few different ways (that way being one of them) - All of which end the same way with the file corrupting.

Is the attach to list a new module added recently? Or has it always been there.... I havent really noticed it until now.

 

Thanks again

Highlighted
Anonymous
Not applicable

Re: Sharepoint: Add Attachments to List Corrupting FIles

Hi @v-yamao-msft

 

Did you manage to investigate this issue at your end?

Many Thanks

Highlighted
Advocate I
Advocate I

Re: Sharepoint: Add Attachments to List Corrupting FIles

In order for the file content to be populated with the right data, you need to select "Content". So your flow action would look something like this:

 

- When a new entry is created (Cognito action)

- Create item (SharePoint action)

- Apply to each (name of your file upload field)

- Add attachment (SharePoint action)

- Site Address, List Name, ID, and File Name are just how you have them in your screenshot

- File Contet = From the Dynamic Content chooser, expand the "When a new entry is created" section and select Content.

 

When I was trying to get this to work, I attempted the same thing as you. I emailed Cognito support to suggest they amend their KB article to illustrate this use case. Their screenshots leave these fields blank, so it's not readily apparent what should be in them: https://www.cognitoforms.com/support/63/data-integration/microsoft-flow

 

Another thing I mentioned to their support and suggest you consider as well. If two file uploads have the same file name (e.g. image.jpg and image.jpg), then you'll want some kind of unique string added to the file name. SharePoint won't allow two files with the same name as attachments to a list item. So Cognito will email you with an integration error notice. I added the function utcNow() in front of the "Name" in the File Name field of the Add attachment action. It adds it to all of the file uploads when attachign to the list item, but at least they're all unique and won't error out. This is a very common situation where iOS devices are uploading directly from their camera instead of choosing from their photo gallery. Androids automatically create a unique file name when uploading directly from the camera.

 

 

Highlighted
Advocate I
Advocate I

Re: Sharepoint: Add Attachments to List Corrupting FIles

In order for the file content to be populated with the right data, you need to select "Content". So your flow action would look something like this:

 

- When a new entry is created (Cognito action)

- Create item (SharePoint action)

- Apply to each (name of your file upload field)

- Add attachment (SharePoint action)

- Site Address, List Name, ID, and File Name are just how you have them in your screenshot

- File Contet = From the Dynamic Content chooser, expand the "When a new entry is created" section and select Content.

 

When I was trying to get this to work, I attempted the same thing as you. I emailed Cognito support to suggest they amend their KB article to illustrate this use case. Their screenshots leave these fields blank, so it's not readily apparent what should be in them: https://www.cognitoforms.com/support/63/data-integration/microsoft-flow

 

Another thing I mentioned to their support and suggest you consider as well. If two file uploads have the same file name (e.g. image.jpg and image.jpg), then you'll want some kind of unique string added to the file name. SharePoint won't allow two files with the same name as attachments to a list item. So Cognito will email you with an integration error notice. I added the function utcNow() in front of the "Name" in the File Name field of the Add attachment action. It adds it to all of the file uploads when attachign to the list item, but at least they're all unique and won't error out. This is a very common situation where iOS devices are uploading directly from their camera instead of choosing from their photo gallery. Androids automatically create a unique file name when uploading directly from the camera.

 

 

Highlighted
Administrator
Administrator

Re: Sharepoint: Add Attachments to List Corrupting FIles

Hello, @Anonymous!

 

Thank you for posting on the Flow Community Forum! Have you had an opportunity to apply @SJNBham‘s recommendation to adapt your Flow? If yes, and you find that solution to be satisfactory, please go ahead and click “Accept as Solution” so that this thread will be marked for other users to easily identify!


Thank you for being an active member of the Flow Community!

 

-Gabriel
Flow Community Manager

-Gabriel
Microsoft Power Automate Community Manager
Are YOU a member of your local Power Automate User Group?
Fill out This Form to claim your Community User Group Member Badge!
Highlighted
Anonymous
Not applicable

Re: Sharepoint: Add Attachments to List Corrupting FIles

Hi @GabrielStJohn,

 

I fixed this a while ago but I cant remember how - Its no longer needed now as the original post was a year ago haha!!

So no, I havent applied any fixes posted recently 🙂

 

Many Thanks

Highlighted
Super User
Super User

Re: Sharepoint: Add Attachments to List Corrupting FIles

This also frustrated me but with the guidance above and some tweaking I got the answer.  I think the issue was mainly in the naming of the file.  So when you add an attachment you need to:

 

1. In the file name box use something like concat(utcNow(),triggerBody()?['Signature']?['Name']) where the trigger is the update or new item created triggers for cognito.  

2. In the File content you simply select Signature Content from the dynamic list

 

Note as advised above I add utcNow to the name as this will make its name unique.  I have not found anthying else that will give a simpler unique ID to the attachment

saveatt.PNG

 

Highlighted
Super User
Super User

Re: Sharepoint: Add Attachments to List Corrupting FIles

Did you get the answer to this?  I do this all the time

Helpful resources

Announcements
firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (7,353)