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.
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
Function Compute is activated. For more information, see Activate Function Compute.
Object Storage Service (OSS) is activated and a bucket is created. For more information, see Create a bucket.
Procedure
Log on to the Function Compute console. In the left-side navigation pane, click Applications.
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.
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.
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.
ImportantMake 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.
NoteTo 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.
Test the application.
Log on to the Object Storage Service (OSS) console and click the bucket that you selected when you created the application.
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
The one-click deployment application described in this topic supports only the decompression of ZIP files. To decompress files in other formats, see decompress-oss.
If you only need to decompress ZIP files uploaded to OSS, you can configure automatic ZIP file decompression directly in OSS. For more information, see Upload and automatically decompress a ZIP package.
To use Function Compute to package and download files from OSS, see Package multiple files into a ZIP archive for download.