This topic introduces how to use veFaaS to automatically decompress Zip files in real time when they are uploaded to Torch Object Storage (TOS).
Scenario introduction
In actual business scenarios, files often need to be uploaded to TOS for storage and usage. To improve efficiency, the business side usually packs up all the files into a Zip archive to upload. However, in practical use, you still need to manually decompress the corresponding Zip archives, which is very inconvenient. Function as a Service combined with TOS Trigger can help you achieve real-time automatic decompression of files after being uploaded to TOS to help you improve work efficiency.
Limits
- It is recommended to avoid using Mac tools to compress files. If you must use the Mac tools to compress files, do not use Chinese characters in file names. Otherwise, this will cause the names of decompressed files to appear as garbled characters and the files cannot function properly.
- TOS Bucket and veFaaS functions must be in the same region.
Prerequisites
- Volcano Engine TOS has been activated.
- Create a bucket (TOS Bucket). For detailed operations, refer to Creating bucket.
- Volcano Engine Function as a Service
- Function as a Service has been activated.
Procedure
Step 1: create a function using a code template
Use the Download compressed package from TOS, decompress, and upload files code template to create a function, and then configure the code information.
- In the top navigation bar, select the target region.
- On the Function page, click Create function.
- Click Create to complete creating the function.
- After successfully creating the function, the system will automatically redirect to the Code tab of the function details page.
- On the Code tab of the function, the code template has provided the business code for automatic decompression. You only need to configure the following information.
- Click Save to save the modified code.
Step 2: Release the function
Release the function code and configuration.
- On the function details page, under the Code tab, click Install dependencies.
- After the dependencies are installed, click Release in the upper-right corner of the page.
- Select Latest as the function version. Other options can be configured as required.
- Click Confirm to release the function.
Step 3: Configure the TOS trigger
Configure the rules of TOS trigger for the function.
- On the function details page, switch to Trigger tab, and click Create Trigger.
- Click Confirm to complete the creation of the TOS trigger.
Validating results
- On the Trigger tab of the current function, select the TOS Trigger created earlier. Click the name of Bucket to redirect to the corresponding Bucket in the TOS console.
- Enter the origin/ directory, click Upload file to submit a Zip archive locally.
- Enter the uncompressed/ directory and you can see the uploaded file is successfully unzipped to the uncompressed/origin directory.