When you need to upload objects in batches, preserve a specific directory structure, upload a complete set of resources, or quickly distribute resources, you can configure a decompression rule. When you upload a ZIP file to a specified path in OSS, it triggers Function Compute to automatically decompress the file and save the extracted content to OSS.
Prerequisites
Function Compute is activated. You can activate the service on the Function Compute product page.
Use cases
-
Batch uploads: If you need to upload a large number of small objects, programmatic uploads can be time-consuming. You can use the ZIP decompression feature to package the objects and upload them as a single archive.
-
Upload complete resources: For resource integrity, you may need to group multiple objects into a single resource. Uploading objects separately can have a lower success rate. The ZIP decompression feature improves the upload reliability for these scenarios.
-
Upload with a specific directory structure: Websites often reference static resources with complex directory structures. Creating each directory and uploading objects one by one in OSS is inefficient. Instead, you can define the directory structure in a ZIP package locally, compress it, and upload it to OSS for automatic decompression.
-
Resource distribution: When you need to distribute a large number of objects to users or servers, you can package them into a ZIP archive. Using the OSS ZIP decompression feature, the archive is automatically extracted to a specified directory upon upload. This reduces transfer time and bandwidth consumption.
How it works
ZIP package decompression uses Function Compute to decompress ZIP files. The following diagram shows the decompression workflow.
-
A ZIP file is uploaded to a directory that matches the prefix specified in the decompression rule.
-
The upload event automatically triggers a function in Function Compute.
When you configure the decompression rule, you must authorize the trigger. This allows OSS to use the trigger role, AliyunOSSEventNotificationRole, to invoke Function Compute. The authorization process automatically grants the necessary policy to the role.
-
Function Compute decompresses the ZIP file and stores the extracted objects in the specified directory in OSS.
When you configure the decompression rule, you must grant permissions to Function Compute. This creates a new role that Function Compute assumes to retrieve the ZIP package from OSS and write the decompressed objects to OSS. When the role is created, a policy that grants read and write permissions on the OSS bucket is attached to the role.
Billing
The ZIP package decompression feature is a value-added service and incurs fees for both OSS and Function Compute. Data is transferred between the bucket and Function Compute over an internal endpoint, so no data transfer fees are charged.
-
OSS: You are charged for API requests and storage. For more information, see OSS billing overview.
-
Function Compute: You are charged for vCPU, memory, and disk usage, billed based on execution duration. For more information, see FC billing overview.
For example, a decompression task runs for 5 minutes (300 seconds) on a function with 2 vCPUs, 3 GB of memory, and a 10 GB temporary disk. The fees are calculated as follows:
Item
Unit
Description
Billing example
vCPU usage
vCPU-seconds
Active vCPU usage = vCPU specification × Execution duration (seconds)
If the function is configured with 2 vCPUs and runs for 300s, the vCPU usage for a single run is 2 × 300 = 600 vCPU-seconds.
Memory usage
GB-seconds
Memory usage = Memory specification × Execution duration (seconds)
If the function is configured with 3 GB of memory and runs for 300s, the memory usage for a single run is 3 × 300 = 900 GB-seconds.
Disk usage
GB-seconds
Disk usage = Disk specification × Execution duration (seconds)
Note: Disk usage up to 512 MB is free of charge.
If the function is configured with a 10 GB temporary disk and runs for 300s, the billable disk usage is (10 - 512/1024) × 300 = 2,850 GB-seconds.
Limitations
-
Storage class: Objects of the Cold Archive or Deep Cold Archive storage class must be restored before they can be decompressed. Objects of the Archive storage class must also be restored if real-time access is not enabled for the bucket.
-
Object and directory naming: We recommend that you use UTF-8 or GB 2312 encoding for your object and directory names. Other encodings may cause garbled names or decompression interruptions.
-
ZIP package: The maximum size for a single object within a ZIP package is 1 GB. The default execution timeout is 2 hours. To extend this time, you can adjust the function's execution timeout. For more information, see Decompression of a large file fails because the task exceeds the 2-hour execution time limit.
Configure a ZIP package decompression rule
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the Buckets page, find and click the desired bucket.
-
In the left-side navigation pane, choose .
-
Click Decompress ZIP Package. In the Decompress ZIP Package panel, configure the decompression rule.
Parameters
Parameter
Required
Description
Service Authorization
Yes
Authorize Function Compute to read from and write to OSS, and to execute functions.
Click Authorize and follow the on-screen instructions.
Authorize Trigger
Yes
Authorize OSS to access Function Compute.
Click Authorize and follow the on-screen instructions. After authorization, this field changes to Trigger Role.
Prefix
No
Specifies an object prefix that triggers the function. The function is triggered when you upload a ZIP file to a directory matching the prefix. If this field is left empty, any uploaded ZIP file triggers the function.
ImportantTo prevent recursive executions, specify a prefix. For more information, see How do I prevent trigger loops?.
Destination Directory
No
The directory where the extracted objects are stored. If you leave this empty, Function Compute extracts the objects to the root directory of the bucket.
-
To create a subdirectory named after the ZIP file, select Add the compressed file name to the path.
-
To extract objects directly into the destination directory without creating a subdirectory, select Decompress directly to the destination directory. See the examples below for details.
WarningTo prevent service disruption, data contamination, or data loss when configuring rules for ZIP package decompression on a bucket with OSS-HDFS enabled, do not set the Destination Directory to
.dlsdata/.Examples
Scenario
Configuration
Directory structure
Decompress all ZIP packages from the zipfolder directory to the destfolder directory without preserving the ZIP package name as a subdirectory.
-
Set Prefix to zipfolder/.
-
Set Destination Directory to destfolder.
-
Select Decompress directly to the destination directory.
bucket ├─── zipfolder/ │ ├─── a.zip│ └─── b.zip└─── destfolder/ ├─── a.txt ├─── b.txt └─── ...Decompress all ZIP packages from the zipfolder directory to the root directory, preserving the ZIP package name as a subdirectory.
Configure the following parameters:
-
Set Prefix to zipfolder/.
-
Leave Destination Directory empty.
-
Select Add the compressed file name to the path.
bucket ├─── zipfolder/ │ ├─── a.zip│ └─── b.zip├─── a/│ ├─── a.txt│ └─── ...└─── b/ ├─── b.txt └─── ...Decompress all ZIP packages from the zipfolder directory to the destfolder directory, preserving the ZIP package name as a subdirectory.
Configure the following parameters:
-
Set Prefix to zipfolder/.
-
Set Destination Directory to destfolder.
-
Select Add the compressed file name to the path.
bucket ├─── zipfolder/ │ ├─── a.zip│ └─── b.zip└─── destfolder/ ├─── a/ │ ├─── a.txt │ └─── ... └─── b/ ├─── b.txt └─── ... -
-
Agree to the terms for activating Function Compute, and then click OK.
Modify a decompression rule
You can modify a ZIP package decompression rule as needed.
Modify the trigger prefix
-
On the Decompress ZIP Package page in the OSS console, find the trigger that you want to modify and click Edit in the Actions column.
-
On the Triggers tab of the function details page, find the trigger and click Modify in the Actions column.
-
In the Edit Trigger dialog box, change the Object Prefix and keep the default settings for other parameters.
-
Click OK.
Modify function configurations
-
On the Configurations tab of the function details page in the Function Compute console, click Modify.
-
Modify the function configurations, such as memory and execution timeout, as needed.
For more information, see Manage functions.
Delete a trigger
A deleted trigger cannot be restored or used to trigger functions. In-progress tasks will continue to run to completion.
-
On the Triggers tab of the function details page, find the trigger that you want to delete and click Delete in the Actions column.
-
In the dialog box that appears, click Delete.
