All Products
Search
Document Center

Function Compute:Automatically decompress compressed files in OSS using Function Compute

Last Updated:Mar 24, 2026

To automatically decompress compressed files that you upload to Object Storage Service (OSS), you can deploy an application with a single click from the Function Compute Application Center. When a ZIP file that matches a decompression rule is uploaded to Object Storage Service, a Function Compute function is automatically triggered to decompress the file. After the file is decompressed, Function Compute uploads the extracted files to a specified directory in Object Storage Service.

Background information

The following flowchart shows the process.

image

Notes

  • Use UTF-8 or GB 2312 encoding for file and folder names. This prevents garbled text or interruptions during decompression.

  • When you upload a compressed file to a bucket, do not select Archive Storage or Cold Archive as the storage class. Otherwise, the function cannot be triggered.

  • A single file within the compressed archive that you upload to a bucket must not exceed 1 GB. If a file is larger than 1 GB, the decompression may fail.

  • The maximum decompression time for a single archive is 2 hours. The task fails if it exceeds this time limit.

  • The default function execution timeout is 2 hours. You can adjust the function execution timeout period as needed.

Prerequisites

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Applications.

  2. On the Applications page, click Create Application. On the Create Application page, a list of creation methods is displayed.

    This topic uses the Use a Template to Create an Application method.

  3. On the Create Application page, find the Auto-decompress ZIP Files Uploaded To OSS card in the templates section. Hover over the card and click Create Now.

  4. On the Create Application page, configure the parameters and click Create And Deploy Default Environment.

    The following table describes the main configuration items. You can use the default values for the other items.

    Configuration Item

    Description

    Basic Configurations

    Deployment Type

    Select Directly Deploy.

    Role Name

    The default role name is AliyunFCServerlessDevsRole. If the current permissions are insufficient, click Add Policy. In the dialog box that appears, select the Add Policy to add, and then click Add.

    Advanced Settings

    RAM Role ARN

    Select the role used to trigger the function from OSS. Make sure that the AliyunOSSFullAccess and AliyunFCDefaultRolePolicy access policies are attached to this role.

    OSS Bucket Name

    Select the created bucket.

    Prefix

    Set the file prefix. The default value is src.

    Important

    Make sure that the prefixes for different triggers in the same bucket are unique. Otherwise, the application fails to be created.

    Destination Directory

    Set the destination directory for the decompressed files. The default value is dst.

    Note

    To prevent the function from being triggered in a loop, set this directory to be different from the Prefix directory.

    Keep Archive Name As Directory

    Specifies whether to keep the compressed file name as a directory in the path. Valid values:

    • true: Keeps the archive name as a directory. For example, if the Destination Directory is target and the archive name is source.zip, the path of the decompressed files is target/source/....

    • false: Decompresses the files directly into the destination directory. In the preceding example, the path of the decompressed files is target/....

    Trigger RAM Role ARN

    The default role is AliyunOSSEventNotificationRole. OSS uses this role to send event notifications to invoke the function.

  5. Test the application.

    1. Log on to the Object Storage Service (OSS) console and click the bucket that you selected when you created the application.

    2. In the destination bucket, upload a .zip file to a directory that matches the Prefix that you set. This action triggers the function to execute. The function automatically decompresses the .zip file and saves the contents to the Destination Directory that you set.

      For example, if you set Prefix to source and Destination Directory to target, when you upload a .zip file to the source or source1 directory, the function is triggered to decompress the file and save the contents to the target directory.

References