Object Storage Service (OSS) can automatically decompress ZIP files. To decompress files in other formats, such as .tar.gz, .tar.bz2, and .tar.xz, you can create an OSS event trigger in Function Compute and code the logic of the trigger to decompress such files. This topic describes how to automatically decompress files that are uploaded to OSS in different formats.


Before you begin, make sure that you have completed the following operations:

Background information

The following flowchart shows the decompression process.principle
Note We recommend that you use the standard ZIP and TAR commands to compress files and use Python 3.6 libraries for your functions to decompress files.

Decompress large files

If a compressed file is large and contains multiple files, decompression may time out and fail to be completed. Function Compute can integrate with Serverless Workflow to decompress a large number of files.

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Application Center.
  3. In the Application Templates section of the Application Center page, click the Other Templates tab.
  4. On the Other Templates tab, move the pointer over Unzip Oss File and click Configure and Deploy.
  5. On the Create Template Application page, set the parameters and click Deploy.
    Note This solution can be used only in the China (Hangzhou), China (Shanghai), China (Beijing), and China (Shenzhen) regions. Only ZIP files can be decompressed.

    If this solution cannot meet your requirements for decompressing large files, you can contact Function Compute engineers. For more information, see Contact us.

Configure decompression for different file formats

  1. Perform the following steps to decompress the sample project:
    • If you have installed Git, run the following command:
      git clone https://github.com/awesome-fc/decompress-oss.git
    • If you have not installed Git, download the code package.
  2. Modify and save the template.yml file.
    1. Change the value of the BucketName parameter from your-bucket to the name of your OSS bucket.
    2. Change the value of the Project parameter from decompress-log-pro to the name of your project. Project names must be globally unique.
    3. When you configure an OSS event trigger, change the values of the Prefix, Suffix, and PROCESSED_DIR parameters as needed. Set the PROCESSED_DIR parameter to the directory where you want to save decompressed files.
      Note By default, OSS event triggers use the src/ prefix and the dst/ directory. For example, you can set the Prefix parameter to src.
  3. In the directory where the template.yml file is located, run the fun deploy command to deploy your project.
  4. After your project is deployed, you can upload compressed files with a .zip, .tar.gz, .tar.bz2, or .tar.xz extension to the specified directory in your OSS bucket. After you upload the files, a function is triggered to decompress the files. The default directory used to store compressed files is src/.
    The function automatically decompresses the files to the specified directory. The default directory used to store decompressed files is dst.