Working with 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.

  1. 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.

  1. Create Attachment Metadata - Creates metadata for the uploaded zip file so we can get the filename

  2. Create Variable - Creates an empty array to store our individual files metadata

  3. For Each Loop - Loops against the array of file resources created in step 2

    1. Conditional - Checks for junk files generated by Mac OS and skips them. This step is optional.

      1. Create Attachment - Creates metadata for the file resource that the loop is currently iterating through

      2. Array: Add to End - Adds the generated metadata to our metadata array established in step 3

  4. Add Record - Adds our metadata to the database

  5. 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.

  1. Zip: Add File Resource - Adds the new file into the existing zip file

  2. 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.

  1. Zip: Delete File Resource - Removes the file matching the filename from the existing zip file

  2. 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.

  1. Zip: Create File Resource - Creates our zip file that we can add to in the rest of the function stack

  2. Zip: Add File Resource - Adds the data from file1 into our zip file

  3. Zip: Add File Resource - Adds the data from file2 into our zip file

  4. 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.

  1. Zip: Create File Resource - Creates our zip file that we can add to in the rest of the function stack

  2. For Each Loop - Loops against our list file resource input

    1. Zip: Add File Resource - Adds the file the loop is currently iterating through to our zip file established in step 1

  3. 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