You can use range download to download a specified range of data from an object.

Specify a valid range to download data

If the start and end values of the range that you specify are within the size of an object, the content within the specified range is downloaded. For example, if the object from which you want to download data is 1,000 bytes in size, the valid range is from byte 0 to byte 999.

The following code provides an example on how to specify a valid range to download:

// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
const accessKeyId = "yourAccessKeyId";
const accessKeySecret = "yourAccessKeySecret";
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
const endpoint = "yourEndpoint";
// Specify the name of the bucket. 
const bucket = "yourBucketName";

async function main() {
  const start = 1, end = 900;
  // Set yourObjectName to the full path of the object. The full path cannot contain the bucket name. 
  // Query the data that is within the range from byte 0 to byte 900, which includes a total of 900 bytes. 
  // If the start or end value of the specified range is not within the valid range, the entire object is downloaded. 
  const result = await client.get("<yourObjectName>", {
    headers: {
      Range: `bytes=${start}-${end}`,
    },
  })
  console.log(result.content.toString())
};

main();

For more information about the naming conventions for buckets, see Bucket. For more information about the naming conventions for objects, see Object.

Specify standard behaviors to download data by range

You can add the x-oss-range-behavior:standard header to the request to modify the download behavior when the specified range is not within the valid range.

The following code provides an example on how to specify standard behaviors to download data by range:

// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
const accessKeyId = "yourAccessKeyId";
const accessKeySecret = "yourAccessKeySecret";
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
const endpoint = "yourEndpoint";
// Specify the name of the bucket. 
const bucket = "yourBucketName";

async function main() {
  // Upload an object named exampleobject.txt. Size: 10 bytes. 
  const buf = Buffer.from("abcdefghij");
  await client.put("exampleobject.txt", buf);
  const result = await client.get("exampleobject.txt", {
  // If you specify a range from byte 5 to byte 15, the value at the end of the range is invalid. Then, OSS returns HTTP status code 206 and the data that is within the range from byte 6 to byte 10. 
    headers: {
      Range: "bytes=5-15",      
      "x-oss-range-behavior": "standard",
    },
  });
  console.log(result.content.toString() === 'fghij')
  console.log(result.res.status === 206)
  try{
    await client.get("exampleobject.txt", {
      // If you specify a range from byte 15 to byte 25, the value at the end of the range is invalid. Then, OSS returns HTTP status code 416 and the error code InvalidRange. 
      headers: {
        Range: "bytes=15-25",        
        "x-oss-range-behavior": "standard",
      },
    })
  }catch(e) {
    console.log(e.status === 416);
    console.log(e.name === 'InvalidRangeError')
  }
}

main();

References

For more information about the API operation that is called to perform range download, see GetObject.