Zip File Support in Power Automate is fairly limited. There are actions to extract files from an archive, but no support for creating your own zip files.
I’ve written before about a method to create Zip files in Power Automate for free using SharePoint.
The SharePoint method described worked, but did not provide any file compression, only stored the requested files. If you need compression, the only option until now, is to use a 3rd party connector but that generally means paying a monthly fee and data leaving your environment.
In this post I will demonstrate a new method for working with Zip Files which uses a custom C# connector, to easily create Zip files in Power Automate or extract files from them.
The key features are:
- You will not have to pay any monthly subscription to an API service.
- The data will not leave your Office 365 environment.
- You can create Zip Files easily.
- You can extract data from Zip files without having to extract the contents to OneDrive or SharePoint first
N.B. Custom connectors require a Power Automate Premium License. So, if you do not have one, this solution is not for you.
Table of contents
Introduction to the Zip Connector
Here is a screenshot of the available actions:
Summary of the actions available:
- Create a Zip File – Will accept an array of files and return a Zip File.
- Extract Zip File Content – Will return an array which contains all the files in the source Zip File (subject to some limitations).
- Extracts a file stored in a Zip Archive – This action extracts a single file from a Zip archive given its path within the Zip.
- List files stored in a Zip Archive – This action returns the list of files contained in the Zip file without the File Content.
Creating a Zip File
Here is the most simple example of the Create a Zip File action in a flow:
The action accepts two Parameters:
- The list of files to be compressed.
- The compression level to apply to the files.
The list of files to be compressed can be manually populated as shown above or provided with a JSON array by clicking on the button to switch to Input Entire Array mode:
This should be an array of objects containing values for Name and Content, like this:
[ { "Name": "Text File.txt", "Content": "VGhpcyBpcyBhIHRlc3QgZmlsZQ==" }, { "Name": "Text File 2.txt", "Content": "VGhpcyBpcyB0aGUgc2Vjb25kIHRlc3QgZmlsZQ==" }, ]
The file content is a Base64 representation of the file. I will provide more detail on this in the sample flows below.
Compression level has four options:
- Optimal – Which provides the best balance between compression and the speed of the operation.
- Smallest – Produces the smallest possible Zip file but takes longer to complete.
- Fastest – Provides the fastest operation but the resulting Zip file will be slightly larger.
Optimal would be the best option in most cases.
The output of the action is a base64 representation of the Zip file, which can be used in subsequent actions to save the Zip file or send in an email etc.
Simple Power Automate Flow to Zip a Single File
Below is a screenshot of the simplest example of how this action can be used:
The flow has three actions:
- Get file content, which provides the input for the Zip action.
- The Create a Zip file action which zips the input.
- The create file action which takes the output from the zip action to create the file.
Example Flow to Zip many files
Take a look at the flow below and the explanation that follows:
Step by step explanation
First, use the Initialize Variable to hold the file content of the files that we want to zip.
Next use the Get Files (properties only) action to get a list of files that we want to Zip. I selected the option to Include nested items and added an odata filter of FSObjType eq 0 to return file objects and not folders.
Next add Get file content using path and supply the file path from the dynamic output of the Get Files action. This will automatically create an apply to each loop.
Next add an Append to array variable action. Supply JSON in the format of:
{ "Name": "", "Content": "" }
For the Name – you can use the dynamic content from the Get Files action. You can also supply the Folder path as per my screenshot if you want the Zip file to retain the paths.
For the content use the output of the Get file content using path action.
Next, outside of the apply to each loop, you can supply the array variable to the Create a Zip file action. Don’t forget to switch the action to entire array mode!
In the final action, I am simply creating a file using the Create File action, using the output from the Zip action. But you could easily change that to a Send an Email action or whatever suits your need.
Example Result
I zipped a SharePoint folder containing 87 files that totalled 55 Megabytes, this resulted in a Zip file of 11 Megabytes.
Password and Encryption Support
The libraries required to create a Zip file with password protection are simply not available in the custom code tool in Power Platform. If you need to create Zip files with Password and Encryption Support I would recommend using Flowr from Encodian.
Working with Existing Zip Archives
Power Automate has two actions for working with Zip Files:
Both of these actions work in a similar way, you specify a source Zip file, a destination folder and it will extract the files for you:
The output from this action is a JSON array of file information which you can then work with to get the file contents, here is some example output:
[ { "Id": "b!Xm9bgFp6o0yRZXE2CnS2bsR4d_A2tk.01CM5RGF5GTCVBUQWV6VGJWZGNKHZ3O3BC", "Name": "2k-Rows.csv", "NameNoExt": "2k-Rows", "DisplayName": "2k-Rows.csv", "Path": "/drives/b!Xm9bgFp64d_A2tk/root:/_zip/ZipExtract/Shared Documents/Zip Test/CSV Files/2k-Rows.csv", "LastModified": "2024-06-27T07:35:40Z", "Size": 140421, "MediaType": "text/csv", "IsFolder": false, "ETag": ""{1AAA98A6-D542-4CF5-9B64-CD51F3B76C22},2"", "FileLocator": "b!Xm9bgFp6o0yRZXE2CnS2bsRojWZetglOshpzGJWZGNKHZ3O3BC", "LastModifiedBy": "Paul Murana" } ]
In many cases the above actions are perfectly adequate, but do require you to write the files out to a folder, and then read them back in again if you want to use the file content in the flow.
The actions included in this connector work in a different way. Instead of extracting the Zip Archive contents to a folder the content of each file in the Zip Archive is returned to the flow for direct use. This makes for a much cleaner flow.
There are three actions for working with Zip archives:
Extract Zip File Content
This action will extract the entire contents of the provided Zip File and return a JSON array of file information and the file content:
Here is a sample of the output:
- All Files Extracted – This informs you that all files were extracted from the archive. This will return false of either the entire size of the output generated would be over 100MB or a single file within the archive is over 100MB.
- File Count – The number of files extracted.
- Files – An array which contains the File information and file data:
- Filepath – The path of the file within the Zip File.
- FilenameWithExtension – Just the Filename without the path.
- FolderPath – The path of the file within the Zip without the File name.
- FileContent – The base64 representation of the File.
The files array can be used in any action that can handle arrays, such as an apply to each loop, a select action or a filter array action.
List files stored in a Zip Archive
This action is the same as the Extract Zip File Content action except it does not return the file content. This is designed so that you can examine the content of the Zip file and then extract specific files with the Extract File action. Example response:
[ { "Filepath": "test file.txt", "FilenameWithExtension": "test file.txt", "FolderPath": "", "FileSize": 14, "OverSizeLimit": false } ]
The output includes an additional property called OverSizeLimit, if the file within the archive is over 100MB this will be true and you will be unable to extract it as it will be over the maximum size of an action that Power Automate allows.
The array of output can be filtered so that you can extract only the files you want to access. You can then use the Extract File action on each file you want to extract.
Extract a file stored in a Zip Archive
Once you have used the List Files action to list the contents of a Zip File, you can then use this action to extract each file from the archive:
The output array of the List Files action can be used as the input for an Apply to each loop and then each file can be extracted from the Zip. Note how the Zip File Content content is the same for both actions.
Limitations
Power Platform Custom Connectors are limited to an execution time of five seconds. This means that if you supply the connector with too much data it will fail.
The connector also returns an additional header of x-processingtime which tells you how long the operation took to process, you can see this in the raw outputs or with an expression:
outputs('Create_a_Zip_file')?['headers']?['x-processingtime']
This will tell you how many milliseconds the operation took, the maximum allowed being 5,000.
Purchase this connector
If you would like to use this connector in your own environment, you can purchase it from Gumroad. You will receive an Zip file containing a solution which you can import into your environment which will make the custom connector available.
How to Import the connector
After you have purchased the connector from Gumroad, importing it is easy:
- Go to https://make.powerautomate.com/
- Select Solutions from the left hand menu:
- Click on Import solution from the top menu:
- Click on the browse button and upload the Zip solution file.
- Click Next.
- Click on Import.
- The solution will now import. This normally takes a few minutes. Then the action will be available in your flows under the custom tab:
Conclusion
This connector provides a really neat way to add Zip functionality to your flows. Crucially your data does not leave your environment and uses only tools already built into your environment.
You will not have to pay a monthly fee to produce Zip files, just a simple one time purchase:
Please let me know in the comments how you get on and if you have any feedback.
Dave Morrison says
looks normal, some files dont compress much at all,, your compression level is set to optimal,, try change that,,
why some files dont compress = https://kb.corel.com/en/125893
Eliot says
People could (could they not?) make a custom connector on a consumption basis in Azure, right?
Then just use that in PA?
Or do you need the licence to USE any Custom Connectors?
Paulie says
There are loads of things you could do. But it wouldn’t work around the license constraint.
Any custom connector needs premium.
Matt says
THANK YOU THANK YOU THANK YOU FOR ALL YOUR BLOGS AND VIDEOS. I really wish you would post a bit often, at least Videos. God bless and have a nice day!
Robert Britton says
Thank you SOOOOOOO much for this connector and explanation. I had spent several hours trying to fix the problem MS caused by changed the security for the HTTP Request to SharePoint action I was previously using. Your solution was WAY easier than the old or trying to fix after the change.
I do have one question: Is there anyway to change the folder structure in the zip file? Basically, I just want the files to appear in the root of the zip file, not the subfolders of the document library.
Thanks!
Paulie says
Yes, when you populate the filename. Provide the filename with extension only instead of the full path to the file.
Really glad it’s working well for you! It’s a much better solution than the SharePoint way and it actually compresses the contents!
Rob says
Thank you, @Paulie! That makes perfect sense.
Paulie says
No worries! I hope you also got my reply to your email!
Rob says
Thank you for asking as I found it was erroneously sent to my junk mail. Thank you for that reply, as well!