cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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!

13 REPLIES 13
v-yamao-msft
Community Support
Community Support

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.
Anonymous
Not applicable

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

Anonymous
Not applicable

Hi @v-yamao-msft

 

Did you manage to investigate this issue at your end?

Many Thanks

SJNBham
Advocate I
Advocate I

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.

 

 

SJNBham
Advocate I
Advocate I

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.

 

 

GabrielStJohn
Microsoft
Microsoft

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
Community Manager
Power Automate | Power Virtual Agents
Super User Program Manager



Anonymous
Not applicable

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

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

 

leyburn19
Memorable Member
Memorable Member

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

But this doesn't work for multiple attachment. I have tried and it keep failing. Please assist

Are you using the content?  Looks to me like you are selecting the File which is not teh content.  There will be a selection in teh list called content or signature content etc

I am but it is not doing it.

Here is what my output looks like for the attachments

"Upload": [
            {
                "ContentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                "Id": "F-LrQp$N6Ke2uEbtNGiP2Dfk",
                "IsEncrypted": false,
                "Name": "New Active Permission Report 2020-08-20.xlsx",
                "Size": 69886
            },
            {
                "ContentType": "video/quicktime",
                "Id": "F-lrqt$gcwD2W5I2ahyPOud!",
                "IsEncrypted": false,
                "Name": "Screen Recording 2020-09-01 at 11.18.31 AM.mov",
                "Size": 6625242
            }

And my flow is set as followed

 

Screen Shot 2020-09-10 at 11.36.54 PM.png

 

but i keep getting this error

Screen Shot 2020-09-10 at 11.36.44 PM.png

Ok,  you need to put a support ticket into cognito for that error.  I had 120000 records working fine and yesterday started getting that error.  Cognito had to fix their mappings in teh background.  My problem is gone.

 

In relation to your attachment.  This may be directly related to the type of teh attachment.   I have two composes before the file gets its name so I get teh correct file type.

 

Compose 1.  Gets teh Content Type

 

Compose 2 has the following expression and looks at the content type and then puts the extension to teh file name based on the type

 

if(contains(outputs('Compose_9'),'heet'),'.xlsx',if(contains(outputs('Compose_9'),'jpg'),'.jpg',if(contains(outputs('Compose_9'),'jpeg'),'.jpg',if(contains(outputs('Compose_9'),'document'),'.docx',if(contains(outputs('Compose_9'),'pdf'),'.pdf',if(contains(outputs('Compose_9'),'png'),'.png',if(contains(outputs('Compose_9'),'stream'),'.msg','')))))))

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

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

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (2,082)