tencent cloud

Feedback

Automatically Decompressing Files with SCF + COS

Last updated: 2023-05-05 15:38:06

    Scenario

    This document describes how to use SCF to automatically decompress files in COS. COS is used to store uploaded .zip files and decompressed files, and SCF automatically decompresses .zip files uploaded to COS.

    Directions

    Creating a bucket

    1. Log in to the COS console.
    2. Click Bucket List on the left sidebar.
    3. Click Create Bucket.
    4. In the Create Bucket dialog box, configure the information as follows:
    4.1 Basic Information
    
    The key parameters are as follows. Retain the default settings for other parameters.
    Name: Enter a custom bucket name. This document uses mybucket as an example.
    Region: Select Guangzhou.
    Access Permission: Select "Private Read/Write".
    4.2 Advanced settings
    Advanced settings are optional and can be set as needed. For parameter details, see Creating Bucket.
    4.3 Configuration confirmation
    Confirm the bucket configurations. If you need to change anything, click Previous and modify as needed.
    5. Confirm the information and click Create to create the bucket. Then, you can view the created bucket on the Bucket List page.

    Configuring decompression function

    1. On the bucket details page, select Function Service on the left sidebar and click ZIP Decompression Function.
    2. Click Add Function and configure the following parameters.
    
    Function Name: A function will be automatically created in the corresponding region. The function name uniquely identifies the function and cannot be modified after creation. You can view the function in the SCF console.
    Event Type: An event is an operation that triggers SCF. Take upload as an example. You can initiate an upload by calling the PUT Object or POST Object API. If you select Creation using Put method as the event type, decompression will be triggered only by a package uploaded via the PUT Object API.
    Note
    If you intend to upload files to the bucket in multiple ways, such as simple upload, multipart upload, and cross-region replication, we recommend that you select All creation events as the event type.
    Trigger Condition: The upload path that will trigger SCF. If you select Specified prefix, SCF will be triggered only when the package is uploaded to a path with the specified prefix. If you choose The whole bucket, SCF will be triggered as long as a compressed file is uploaded to any location of the bucket.
    Note
    If the destination file prefix configured overlaps with the trigger condition, a loop may be triggered, which should be avoided. For example, if the destination file prefix is prefix, and the trigger condition is pre, a decompression loop will be triggered when you upload a pref package.
    SCF Authorization: This authorization is required, because decompression requires you to authorize SCF to read the package from your bucket and upload the decompressed files to the specified location.
    3. Click Next and configure the following in the pop-up window:
    Decompression Format: The decompression formats you are allowed to use. Currently, only ZIP files are supported.
    Destination bucket: A bucket to store the decompressed files.
    Destination path: Decompress the matched files into this destination directory. To prevent unnecessary fees from triggering the loop, we recommend that you set a destination directory different from the prefix.
    Extra prefix: The specific path for storage of the files after a package is decompressed. If this parameter is not set, it will be the root directory of the bucket by default. For more information, see Configuring Auto ZIP File Decompression in the Console.
    Forbid recursive triggering: Enable does not continue to decompress ZIP packages that are decompressed from the package, while Disable does.
    Callback URL: Enter the callback URL as needed.
    4. Click Confirm. You can perform the View Log operation on the newly created function to view the history of decompression. If an error occurs during decompression, you can quickly enter the SCF console to view the error details by selecting View Log. If you need to delete a file decompression rule no longer used, select Delete to delete the relevant configuration.

    Testing the function

    1. On the bucket management page, select File List on the left.
    2. On the file list page, click Upload Files and select a .zip file for upload.
    
    3. Refresh the current bucket to check whether files are generated after decompression.
    4. Switch to Function Service to view the log or enter the SCF console to view the execution result, and you will see the printed log information in Log Query.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support