Working with Zip Files
Viewing zip file contents
Learn how to view the contents of a zip file
Extracting a zip file
Learn how to extract a zip file
Adding files to a zip file
Learn how to add new files to an existing zip file
Removing files from a zip file
Learn how to remove files from an existing zip file
Creating a zip File from Scratch
Learn how to create a zip file in your function stack
A note about encryption
Make sure you are choosing the right encryption method for passworded zip files
Viewing Zip File Contents
In this example, all we want to do is upload a zip file and review its contents in our function stack.
We've added our file resource input to ingest the file, and then utilize the Zip: View Contents function, targeting our file resource input. We can also provide a password to this function if our zip file requires one to open.
Zip: View Contents - Returns the contents of our zip file to a variable
Extracting a Zip File
In this example, our users will be uploading a zip file. We then want to extract all of those files from the zip file in order to add those files individually to our database.
Create Attachment Metadata - Creates metadata for the uploaded zip file so we can get the filename
Create Variable - Creates an empty array to store our individual files metadata
For Each Loop - Loops against the array of file resources created in step 2
Conditional - Checks for junk files generated by Mac OS and skips them. This step is optional.
Create Attachment - Creates metadata for the file resource that the loop is currently iterating through
Array: Add to End - Adds the generated metadata to our metadata array established in step 3
Add Record - Adds our metadata to the database
Delete File - Deletes the zip file. This is only necessary if you generate metadata for it as we did in step 1.
Adding to a zip file
In this example, our users are uploading a zip file, and we want to add another file to that same zip file. We have two file resource inputs: one is for the zip file, and one is for the new file to add.
Zip: Add File Resource - Adds the new file into the existing zip file
Zip: View Contents - Allows us to view the contents of the updated zip file
Removing from a zip file
In this example, our users are uploading a zip file, as well as specifying a file to remove, and we want to remove that file from the zip file. We have two inputs: a file resource input for the zip file, and a text input for the file name to remove.
Zip: Delete File Resource - Removes the file matching the filename from the existing zip file
Zip: View Contents - Allows us to view the contents of the updated zip file
Creating a zip file from scratch
In this example, our users are uploading multiple files, and we want to store them inside of a zip file.
From multiple file resource inputs
In this scenario, we have multiple file resource inputs for each incoming file.
Zip: Create File Resource - Creates our zip file that we can add to in the rest of the function stack
Zip: Add File Resource - Adds the data from file1 into our zip file
Zip: Add File Resource - Adds the data from file2 into our zip file
Zip: View Contents - Allows us to review the zip file contents after completion
From an array of files via a single file resource input
In this scenario, we have a single file resource input, formatted as a list. This is good if you need to dynamically determine how many files your API is ingesting.
Zip: Create File Resource - Creates our zip file that we can add to in the rest of the function stack
For Each Loop - Loops against our list file resource input
Zip: Add File Resource - Adds the file the loop is currently iterating through to our zip file established in step 1
Zip: View Contents - Allows us to review the zip file contents after completion
A note about encryption
Xano supports creating and working with encrypted zip files. In the zip functions available, you'll notice one or both of the following fields:
The password field is to set the password you want applied to the zip file.
The password_encryption field is available for you to set the encryption method applied to the zip file upon creation. The following encryption methods are available:
Standard - This is the most compatible form of encryption (Traditional PKWARE encryption). This is required if you need to be able to extract your zip files using Windows' native zip extraction.
AES-128
AES-256
AES-512
Last updated