All Products
Search
Document Center

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

Last Updated:Apr 17, 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. Then, on the Create Application page, select a creation method.

    This topic uses Use a Template to Create an Application as an example.

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

  4. On the Create Application page, configure the following parameters and then 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 is AliyunFCServerlessDevsRole. If the current permissions are insufficient, click Add Policy, select the required policy in the dialog box and click Add.

    Advanced Settings

    RAM role ARN

    Select the role that OSS uses to trigger the function. 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 a different path from the one specified for Prefix.

    Keep archive name as directory

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

    • true: Creates a subdirectory. For example, if the Destination Directory is target and the archive is named source.zip, the extracted files are saved to 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 selected bucket, upload a .zip file to a path that starts with the configured Prefix. This triggers the function to automatically decompress the file and save its contents to the specified Destination Directory.

      For example, if you set Prefix to source and Destination Directory to target, uploading a .zip file to a path such as source/data.zip or source1/test.zip triggers the function. The extracted files are then saved to the target directory.

References