Optimize Zip File Updates with Power Automate
Bildquelle: Shutterstock.com
Power Automate
1. Dez 2023 05:00

Optimize Zip File Updates with Power Automate

von HubSite 365 über David Wyatt [MVP]

Senior Staff Engineer - Intelligent Automation Developer

Citizen DeveloperPower AutomateLearning Selection

Master Zip File Editing with Power Automate & SharePoint API!

One of the great features of Power Automate is that it functions as an API caller, much like how Postman works, meaning nearly anything is possible with the correct API. However, editing zip files while keeping the contents in a zip format is a bit tricky since there's no native "zip" action. Luckily, SharePoint can handle zip files for bulk downloads through its API, used in conjunction with the SharePoint HTTP connector.

For example, suppose you have a text file in a zip format that needs editing. You can upload the original file, execute your edits, and have the updated file saved back to SharePoint utilizing Power Automate.

  • Unzip the file using an out-of-the-box action
  • Filter and edit the file contents as necessary
  • Re-zip the file using SharePoint's API

Consider the scenario where I have a "hello world" text file inside a zip and I want to change it to "goodbye world." This could be triggered by an upload button, with the desire to have the output file created in SharePoint. To achieve this, there are three critical steps: Unzipping the file, editing the contents, and rezipping the file.

The unzipping process uses the out-of-the-box SharePoint or OneDrive action, which takes the zip file as an input and creates a folder with the unzipped contents. Next, editing the file is fairly straightforward for text-based files like txt, json, xml, or html. You filter the needed file from the unzipped folder, modify the content with a "replace()" expression, and prepare it for rezipping.

Rezipping the updated contents is the trickier part. It involves making HTTP requests to gather folder data from SharePoint, creating the zip payload with necessary details such as file names and sizes, and then initiating the zip process. This is done by using a Microsoft service URL obtained from a previous HTTP request, crafting an array with items to be zipped, and sending a final request for the SharePoint service to compile a new zip file.

Last, you’ll create or replace the zip file in SharePoint using a "create file" action combined with a "base64ToBinary()" expression on the HTTP response content. This method isn't just for regular zip files but can also be applied to "secret zip files," which are file extensions that act as zip files. For instance, Word .docx files and Excel .xlsx files are essentially zip files in disguise and can be modified by renaming them to .zip, making the necessary edits, and then reverting them back to their original extension.

Understanding Power Automate’s Zip File Manipulation

Power Automate, Microsoft's versatile automation tool, enables users to automate workflows across various applications and services. One advanced capability is manipulating zip files using SharePoint’s API, a feature not natively present within Power Automate’s actions. By leveraging SharePoint as a workaround, users can unzip, edit, and rezip files without needing third-party actions. This technique is particularly useful for various file types that are inherently zip files, like Office document formats, allowing for automated content updates and management directly within SharePoint.

Read the full article How to update contents of a Zip file with Power Automate

Power Automate - Optimize Zip File Updates with Power Automate

Keywords

Update Zip Power Automate, Modify Zip Files Power Automate, Automate Zip File Updates, Power Automate Edit Zip, Power Automate Refresh Zip Content, Manage Zip Files with Power Automate, Power Automate Zip Automation, Zip File Automation Power Automate, Update Zip Content Flow, Power Automate Change Zip Files.