Zipping and Unzipping Files Using Salesforce B2C Commerce Script

If you have large files, we recommend that you zip them for file transfer. You can automate the zip process if you are using a pipeline to transfer files by creating scripts.

The B2C Commerce API supports the creation and extraction of .zip files.

  • File.zip(File outputZipFile) creates a new .zip file from the contents of this file. If the file is a directory, the .zip file is created from the contents of files in the directory. If the output .zip file exists, it's replaced with a new .zip file. Empty subdirectories are not zipped. Zip entry names (pathnames) are made relative to this file. This approach facilitates unzipping the contents into a different directory.
  • File.unzip(File root) extracts the content of this .zip file into the location designated by the root. If the .zip file contains directories, those directories are created as needed. If a file already exists, it's overwritten.

Example:

var catalog: File = new File('/catalog');
catalog.zip('/temp/catalog.zip');
var catalogZip : File = new File('/temp/catalog.zip');
catalogZip.unzip('/temp/catalog'); // /temp/catalog created to store unzipped contents.