Power Automate - Unzip And Upload SharePoint List Attachments To Document Library

In this article, we will see how you can use Power Automate flow to get the SharePoint list attachment (zip file) and unzip it. This flow will unzip the files and upload the unzipped files to a SharePoint document library. First flow will get the zip attachment, upload it to document library within a sub site and then it will unzip the files to the same document library. At the end, flow will remove the zip file from the document library and will keep only unzipped files.

Trigger

This flow will trigger when item is created or updated in the list which has zip attachment.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Initialize Variables

We will define the following variables:

  • Initialize variable - Site Title: Title of the site where document library exists.
  • Initialize variable - Site Url: URL of the site where document library exist.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Flow Logic

First, we will get all the zip attachments from the list and then loop through each attachment. For each attachment we will get attachment content and then will recreate same zip file in subsite document library. Next, unzip files to the document library and delete the zip file in library.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Get attachments

Use ‘Get attachments’ action of SharePoint to get all list attachments. Pass ID of the item at input.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Get attachment content

Use ‘Get attachment content’ action of SharePoint to get content of each attachment. Pass ID of the item and Id of attachment @{items('Apply_to_each_attachment')?['Id']} as input.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Create file

Use ‘Create file’ action of SharePoint to create zip file in document library of subsite.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Pass subsite URL, library name, File Name, and File Content

File Name: @{items('Apply_to_each_attachment')?['DisplayName']}

File Content: @{body('Get_attachment_content')}

Extract folder - unzip files to the documents library

Use ‘Extract folder’ action of SharePoint to unzip files to the documents library. Zip file inside the library is unzipped inside the library.

Power Automate: Unzip and upload SharePoint list attachments to Document library

Source File Path: /Shared Documents/@{outputs('Create_zip_file_in_Sub_site_library')?['body/Name']}

Destination Folder Path: /Shared Documents

Delete file - Remove zip file

Use ‘Delete file’ action of SharePoint to delete zip file from the library. Pass Id of zip file to delete.

Power Automate: Unzip and upload SharePoint list attachments to Document library

File Identifier: @outputs('Create_zip_file_in_Sub_site_library')?['body/Id']

Finally, flow will loop through all the attachments in the list, upload it to library, unzip and delete the zip file.


Similar Articles