tencent cloud

masukan

Using API to Decompress GZIP Files

Terakhir diperbarui:2022-05-11 14:27:47

    Prerequisites

    1. The GZIP decompression feature is implemented via the Serverless Cloud Function (SCF) service. Before use, you need to go to App Integration > GZIP Decompression in the COS console to create a GZIP Decompression function. For detailed directions on how to create a function, see Using Console to Configure Auto GZIP File Decompression.
    2. After creating the function, click Instructions on the right of the function to configure it. The configuration items are a JSON string, which will be as described in detail in this document.
    • If your function needs SCF authentication, you need to call the Invoke API provided by SCF to run your cloud function, where the ClientContext parameter is passed in JSON format (see Sample Function Parameter Configuration for details).
    • If you configure the function to be authentication free, you can directly send HTTP requests to the corresponding API gateway to call the function.

    Sample Function Parameter Configuration

    Note:

    In actual practice, delete the comments in the code.

    {
      "bucket": "examplebucket-1250000000",    // Source bucket storing the GZIP package
      "region": "ap-guangzhou",         // Region where the source bucket storing the GZIP package resides
      "key": "example.txt.gz",              //  GZIP package name
      "targetBucket": "examplebucket-1250000000",    // Destination bucket to store the decompressed objects
      "targetRegion": "ap-guangzhou",         // Region where the destination bucket resides
      "targetPrefix": "target/",              // Prefix of the directory to store the decompressed objects
    }
    

    The parameters are as described below:

    Parameter Description Type Required
    bucket Source bucket storing the GZIP package in the format of BucketName-APPID, such as examplebucket-1250000000. String Yes
    region Region of the source bucket storing the GZIP package. For the enumerated values, see Regions and Access Endpoints. String Yes
    key GZIP package name (object name), which is the unique identifier of the object in the bucket. For more information, see Object Overview. String Yes
    targetBucket Destination bucket to store the decompressed objects in the format of BucketName-APPID, such as examplebucket-1250000000. String Yes
    targetRegion Destination bucket region. For the enumerated values, see Regions and Access Endpoints. String Yes
    targetPrefix Prefix of the directory to store the decompressed objects. End a specified directory with a slash for saving to this directory, or keep it empty for saving to the root directory. String No

    Sample Function Response

    {
       "code": 0,
       "message": "cos gunzip file success",
       "data": {
           "Bucket": "examplebucket-1250000000",
           "Region": "ap-guangzhou"
       }
    }
    

    Response parameters are as described below:

    Parameter Description Type
    code Business error code. 0: The execution is successful. Other values: Execution failed. Number
    message Text description of the execution result. The message may be null. String
    data Information of successful execution. If the execution is successful, it contains information of the destination bucket. Object
    error Execution failure information. If the execution is successful, this parameter is null. Object or String

    Use Cases

    Use case 1: Decompressing a *.gz file

    Parameter configuration

    {
    "bucket": "examplebucket-1250000000",
    "region": "ap-guangzhou",
    "key": "example.txt.gz",
    "targetBucket": "examplebucket-1250000000",
    "targetRegion": "ap-guangzhou",
    "targetPrefix": "target/"
    }
    

    Location of decompressed objects

    target/example.txt
    

    Use case 2: Decompressing *.tar.gz and *.tgz files

    Parameter configuration

    {
     "bucket": "examplebucket-1250000000",
     "region": "ap-guangzhou",
     "key": "example.tar.gz",
     "targetBucket": "examplebucket-1250000000",
     "targetRegion": "ap-guangzhou",
     "targetPrefix": "target/"
    }
    

    Compressed package structure

    example.tar.gz
      ├── example-subfile-1.txt
      ├── example-subfile-2.png
      └── example-subfile-3.mp4
    

    Location of decompressed objects

    target/example-subfile-1.txt
    target/example-subfile-2.png
    target/example-subfile-3.mp4
    
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24