cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BenChainCode
Frequent Visitor

Get sharepoint item attachment and save to folder

Hi

 

I am building a powerapp with sharepoint behind it. 

 

The user enters sharepoint list information on a form in the powerapp and may add attachments. 

 

We want those attachments to also be saved separately to a directory folder.

 

I can't seem to find a reference to the attachments in any of the connectors. 

 

Is this possible? 

1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Community Champion
Community Champion

SharePoint List item attachments are stored in the Attachments folder:

.../Lists/<ListName>/Attachments/[ID]/filename.xxx

where [ID] is the SharePoint item ID

Example:

ekarim2020_0-1631205606525.png

Site: name: ContractsRepo

List name: Contracts Library

List Item ID: 52

Attachment name: Diskeeper Dashboard Summary Report.pdf

https://tenancyname.sharepoint.com/sites/ContractsRepo/Lists/Contracts%20Library/Attachments/52/Diskeeper Dashboard Summary Report.pdf

To get all attachments for a SharePoint List item, your flow will resemble something similar to below. The attachment(s) is stored in an array and sent in an Approval:

ListitemAttachments.jpg

 

 

 

{
  "name": @{outputs('Get_file_metadata')?['body/DisplayName']},
  "content": {
    "$content-type": @{body('Get_attachment_content')['body']['$content-type']},
    "$content": @{body('Get_attachment_content')['body']['$content']}
  }
}

 

 

 

ekarim2020_2-1631208402984.png

ekarim2020_0-1631208215560.png

To save the attachments to a SharePoint document library, the varAttachment arrary needs the following format:

ekarim2020_3-1631208605852.png

Use a loop to save each attachment to a document library:

ekarim2020_5-1631208979364.png

Hope this helps.

Ellis

View solution in original post

7 REPLIES 7
ekarim2020
Community Champion
Community Champion

SharePoint List item attachments are stored in the Attachments folder:

.../Lists/<ListName>/Attachments/[ID]/filename.xxx

where [ID] is the SharePoint item ID

Example:

ekarim2020_0-1631205606525.png

Site: name: ContractsRepo

List name: Contracts Library

List Item ID: 52

Attachment name: Diskeeper Dashboard Summary Report.pdf

https://tenancyname.sharepoint.com/sites/ContractsRepo/Lists/Contracts%20Library/Attachments/52/Diskeeper Dashboard Summary Report.pdf

To get all attachments for a SharePoint List item, your flow will resemble something similar to below. The attachment(s) is stored in an array and sent in an Approval:

ListitemAttachments.jpg

 

 

 

{
  "name": @{outputs('Get_file_metadata')?['body/DisplayName']},
  "content": {
    "$content-type": @{body('Get_attachment_content')['body']['$content-type']},
    "$content": @{body('Get_attachment_content')['body']['$content']}
  }
}

 

 

 

ekarim2020_2-1631208402984.png

ekarim2020_0-1631208215560.png

To save the attachments to a SharePoint document library, the varAttachment arrary needs the following format:

ekarim2020_3-1631208605852.png

Use a loop to save each attachment to a document library:

ekarim2020_5-1631208979364.png

Hope this helps.

Ellis

View solution in original post

Thanks for the fast response. 

 

What is the last File Content field? ContentBytes.$...something. I don't have it as selectable dynamic content

ekarim2020
Community Champion
Community Champion

The last ContentBytes expression is:

items('Apply_to_each_2')['ContentBytes']['$content']

I had taken the screen shots from two different working flows.

ekarim2020_1-1631283372043.png

ekarim2020_4-1631283736686.png

 

Ellis

 

 

Before you responded I tried it simply using the Attachment Content option that was available and it does seem to work. The flow itself results in an FAIL but the attachments are saved so I'm not sure why it is failing. 

 

Thanks for your assistance 🙂

ekarim2020
Community Champion
Community Champion

Can you share your update flow, along with any expressions.

Ellis

Updating to your provided expression works without issue 🙂 

BenChainCode
Frequent Visitor

@ekarim2020 Hmm so upon closer inspection, while the files were saving to folders. On opening the file, it seems they were corrupted.

 

All the files are saved as 52 bytes. Seems only the file name is actually being saved and not the content of the file. I assume I missed a step but I can't spot it. 

 

My flow: 

  1. Trigger: When a list item is created
  2. Create New folder
  3. Get attachments from list item id
  4. Initialise variable: Array, varAttachments
  5. Apply to each (get attachments body):
    1. Get attachment content: id=trigger id, file identifier= apply to each id
      Get file metadata = apply to each id
    2. Append to array variable
      1. {
        "name": @{outputs('Get_file_metadata')?['body/DisplayName']},
        "ContentBytes": @{body('Get_attachment_content')?['body']}
        }
    3. Apply to each (varattachment)
      1. Create file: file content = items('Apply_to_each_3')['ContentBytes']['$content']

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,338)