All Products
Search
Document Center

Object Storage Service:Package and download objects as a ZIP file

Last Updated:May 07, 2026

Object Storage Service (OSS) integrates with Function Compute, allowing you to build various applications and functions. This topic explains how to use Function Compute to package multiple OSS objects into a single ZIP file for local download.

Prerequisites

How it works

Downloading multiple objects from OSS in bulk, especially many small ones, can be slow and inconvenient. By using Function Compute, you can package the objects on OSS first, download the compressed package to your local computer, and then decompress it. This method enables faster bulk downloads. The workflow for using Function Compute to package and download OSS objects is shown in the following figure.压缩OSS文件

  1. A user invokes the function and specifies the bucket and objects to be compressed.

  2. Function Compute downloads the specified objects from OSS and generates a ZIP package with a random name.

  3. Function Compute uploads the ZIP package to OSS.

  4. Function Compute returns the download URL of the ZIP package to the user.

  5. The user downloads the file from OSS using the returned permanent download URL.

Usage notes

  • The disk space in the function's runtime environment is limited. Therefore, the function streams data for both downloads and uploads to cache only a small amount of data in memory.

  • To accelerate the process, Function Compute uploads the ZIP file to OSS while it is being generated.

  • When uploading the ZIP file to OSS, the function uses the multipart upload feature of OSS to upload parts concurrently through multiple threads.

  • The maximum processing time for compressing files using Function Compute is 24 hours. (Test data: 57 objects with a total size of 1.06 GB were processed in 63 seconds).

Procedure

This example describes how to use Function Compute to package and download multiple objects from the dir/ directory in the examplebucket bucket in the China (Hangzhou) region to a local computer.

  1. Deploy the application and obtain its public domain name.

    One-click with ROS

    Use Resource Orchestration Service (ROS) to deploy the Function Compute application in one click.

    1. Open the one-click configuration template link.

    2. On the Configure Parameters tab, keep the default settings for all parameters and click Next: Check and Confirm.

    3. On the Check and Confirm tab, click Create.

      The Status on the Stack Information tab shows Creating.

    4. When the Status of the stack changes to Create_Success, click the Outputs tab to find the public domain name.

    One-click with Serverless Application Center

    1. Deploy the start-zip-oss application template from Serverless Application Center.

      For the deployment type, select Directly Deploy. Ensure the application template and the bucket are in the same region. Keep the default settings for other options. The configuration is shown in the following figure.1

    2. Obtain the public domain name.

      1. Click the Result tab.

      2. In the triggers field, obtain the public domain name (urlInternet).

        2

    Manual with Serverless Devs CLI

    1. Install Serverless Devs.

      npm install -g @serverless-devs/s

      Verify the installation.

      s -v

      The following output indicates a successful installation:

      @serverless-devs/s: 2.1.1, s-home: /root/.s, linux-x64, node-v14.19.3
    2. Configure Serverless Devs.

      s config add --AccessKeyID LTAI******** --AccessKeySecret  KZo1******** --access fc-access

      The following table describes the parameters.

      Parameter

      Description

      --AccessKeyID

      The AccessKey ID for accessing Function Compute.

      --AccessKeySecret

      The AccessKey Secret for accessing Function Compute.

      --access

      A custom alias for the credentials.

    3. Deploy the start-zip-oss application template.

      1. Initialize the project.

      2. s init start-zip-oss -d start-zip-oss
      3. Specify values for the configuration items based on the following examples.

      4. Parameter

        Example

        Region where the application is located

        cn-hangzhou

        Function Compute service to which the application belongs

        start-zip-oss

        Function name of the application

        zip-oss-func

        ARN of the RAM role configured for the Function Compute service to which the application belongs

        acs:ram::137918634953****:role/test-role

      5. Go to the project directory.

      6. cd start-zip-oss
      7. Deploy the project.

      8. s deploy -y
      9. Record the system_url from the output.

      10. fc-zip-oss-service:
          region:   cn-hangzhou
          service:
            name: start-zip-oss
          function:
            name:       zip-oss-func
            runtime:    python2.7
            handler:    main.main_handler
            memorySize: 3072
            timeout:    1800
          url:
            system_url: https://zip-oss-func-start-zip-oss-ayouye****.cn-hangzhou.fcapp.run
          triggers:
            -
              type: http
              name: http-test
  2. On your server or an ECS instance, run the following command to generate an event.json file. In the file, specify the bucket name and the directory that contains the objects to be downloaded.

    cat <<EOF > event.json
    {
      "bucket": "examplebucket",
      "source-dir": "dir/"
    }
    EOF
    Note

    The source-dir parameter must be a directory within a bucket; the root directory is not supported.

  3. The following command is a sample request.

    curl -v -L -o  oss.zip -d @./event.json https://zip-oss-func-zip-oss-ayouye****.cn-hangzhou.fcapp.run
    • oss.zip: The local path where the downloaded ZIP package is saved.

      Note

      If the built-in Windows decompression tool fails, use a third-party tool, such as 7-Zip or WinRAR.

    • https://zip-oss-func-zip-oss-ayouye****.cn-hangzhou.fcapp.run: the system_url returned when you deploy the project.

    To invoke this as an authenticated HTTP function instead of an anonymous one, use one of the following SDKs:

FAQ

Adding watermarks

No. However, you can add text or image watermarks to objects in OSS by using the following methods:

  • For objects with public-read or public-read-write permissions

    Add watermark parameters to the object URL. For more information, see Image watermarks.

  • For objects with private permissions

    Add watermarks by including image processing parameters or image style parameters in the SDK. For more information, see Process images by using SDKs.

Time-limited download URLs

No. To create a URL with an expiration time, you must generate a signed URL that includes the Expires parameter. For more information, see Use object URLs.

References