When you download objects from Object Storage Service (OSS), it may be inconvenient to download them one by one if the objects are small in size but large in number. You can use Function Compute to package and download multiple objects from OSS to your on-premises computer at a time. This solution allows you to quickly download multiple objects at lower costs.
Process and principles
Process
The following flowchart describes the process of downloading multiple objects from OSS at a time by using Function Compute:
A user invokes a function and specifies the OSS bucket and objects to be compressed.
Function Compute downloads objects from OSS and compress the objects into a ZIP file.
Function Compute uploads the ZIP file to OSS.
Function Compute returns the URL of the ZIP file in OSS.
Download the ZIP file by using the URL that is returned in Step 4.
Principles
The following figure shows how Step 2 and Step 3 in the preceding flowchart are implemented.
This solution brings the following benefits:
The streaming download and upload method is used. This way, only a small amount of data is cached in the memory and the limited disk space of function running environments is not consumed.
The multipart upload feature of OSS is used to concurrently upload parts of the ZIP file in queues in multi-threaded mode.
Run the following command to initialize a project:
sudo s init start-zip-oss -d start-zip-oss
Run the following command to access the project and deploy the project:
cd start-zip-oss && sudo s deploy - y
After the deployment, an output that is similar to the following code snippet is returned. Records the value of system_url. The value is used when you invoke the function.
Use the curl command to directly invoke the function.
Create a folder in the start-zip-oss directory to store compressed files. In this example, tmp folder is used. The following code snippet shows an example of curl command:
Note
Replace the endpoint in the sample command to the value of system_url that is returned after the application is deployed.
After the invocation, you can view the downloaded compressed file in the start-zip-oss/tmp folder. Log on to the OSS console and view the downloaded compressed files in the output directory of the bucket.
Test data
Test
Number of objects
Total size before compression
Total size after compression
Execution duration
Test
Number of objects
Total size before compression
Total size after compression
Execution duration
1
7
1.2 MB
1.16 MB
0.4s
2
57
1.06 GB
0.91 GB
63s
Description:
Test 1 shows that the storage space of objects are reduced if you use Function Compute to download multiple objects at a time.
Test 2 shows that a large number of objects can be downloaded in a short period of time if you use Function Compute to download multiple objects at a time.
If you want to associate more than 10 triggers with a bucket, you can create EventBridge-based OSS triggers. For more information, see Configure an EventBridge-based OSS trigger.