Choose where you’d like to start

compress

Note: This function is applicable to all Zoho services. In Zoho Creator, this function can be applied only on files fetched using the invokeUrl task and not on the files fetched from Zoho Creator fields.

Overview

The compress function compresses one or more files into a single ZIP file of .zip format. 

Note:
  • This function cannot return a zip file of size more than 2 MB. If the size exceeds the limit an error will be thrown.

Return Type

Syntax

<variable> = <files>.compress([<compressed_file_name>]);

where,

ParameterData typeDescription
<variable>FILEThe compressed file
<files>FILE/ LIST/ KEY-VALUE

Files that need to be zipped

  • If a single file needs to be compressed, it is supplied to this parameter as FILE.
  • If more than one file needs to be compressed, they are supplied to this parameter as LIST.
  • If the files need to be compressed and structured as directories, they are supplied to this parameter as KEY-VALUE. Its values can either be FILE representing the file to be included in the directory, or KEY-VALUE representing the directory that needs to be nested within it. To insert a file, the keys need to be the name of the file that needs to be compressed. To insert a directory, the keys need to be a TEXT representing the name of the directory that needs to be created.
Note: To fetch the name of a file, you can use the get file name task
<file_name>

​(optional)
TEXT

Name with which the compressed file needs to be returned

Note: Please make sure the file name doesn't contain any restricted characters.

Example 1: Compress a file

The following example compresses a file fetched from cloud: 

 file1 = invokeUrl
 [
   url :"http://www.africau.edu/images/default/sample.pdf"
   type :  GET
 ];
 
 zip_file = file1.compress("compressed_file");
 

where:

zip_file
The FILE that holds the compressed file.

Example 2: Compress more than one file

The following example compresses a list of files and returns a compressed .zip file: 

 // Fetch .pdf file
 file1 = invokeUrl
 [
   url :"http://www.africau.edu/images/default/sample.pdf"
   type :  GET
 ];
 
 // Fetch .jpg file
 file2 = invokeUrl
 [
   url :"https://upload.wikimedia.org/wikipedia/commons/a/a7/Blank_image.jpg"
   type :  GET
 ];
 
 // Create a list to add files that need to be compressed
 filesList = List();
 filesList.add(file1);
 filesList.add(file2);
 
 // Perform compress function
 zip_file =  filesList.compress("compressed_file");
 

Example 3: Compress file and format them in directories

The following example compresses two files and arranges in the structure:

  • Directory 1 contains File 1 and Directory 2
  • Directory 2 contains File 2
 // Fetch .pdf file
 file1 = invokeUrl
 [
   url :"http://www.africau.edu/images/default/sample.pdf"
   type :  GET
 ];

 // Fetch .jpg file
 file2 = invokeUrl
 [
   url :"https://upload.wikimedia.org/wikipedia/commons/a/a7/Blank_image.jpg"
   type :  GET
 ];
 
 // Create a map to add files in directory structure
 directory2 = Map();
 directory2.put(file2.getfilename() ,file2);

 directory1 = Map();
 directory1.put(file1.getfilename() ,file1);
 directory1.put("Directory 2" ,directory2);
 
 // Perform compress function
 zip_file =  directory1.compress("Directory 1");
 

where:

zip_file
The FILE that represents the compressed file. This example returns Directory 1.zip.
directory1
The KEY-VALUE variable that holds the files that need to be compressed in the required structure.
"Directory 1"
The TEXT that represents the name of the compressed file.

Related Links

Get Started Now

Execute