The transfer acceleration feature allows users worldwide to access objects stored in Object Storage Service (OSS) in a short period of time. This feature is suitable for scenarios where data must be transferred over long geographical distances. This feature can also be used to download or upload large objects that are gigabytes or terabytes in size.

Usage notes

  • In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS by using other Alibaba Cloud services in the same region as OSS, use an internal endpoint For more information about the regions and endpoints supported by OSS, see Regions and endpoints.
  • In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or STS, see Initialization.

Enable transfer acceleration

The following code provides an example on how to enable transfer acceleration for a bucket named examplebucket:
import oss2

# 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. 
auth = oss2.Auth('yourAccessKeyId', '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. 
# Specify the name of the bucket. Example: examplebucket. 
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# Configure transfer acceleration for the bucket. 
# If enabled is set to true, transfer acceleration is enabled. If enabled is set to false, transfer acceleration is disabled. 
enabled = 'true'
bucket.put_bucket_transfer_acceleration(enabled)

Query the transfer acceleration status of a bucket

The following code provides an example on how to query the transfer acceleration status of a bucket named examplebucket:

import oss2

# 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. 
auth = oss2.Auth('yourAccessKeyId', '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. 
# Specify the name of the bucket. Example: examplebucket. 
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# Query the transfer acceleration status of the bucket. 
# If the returned value is true, the transfer acceleration feature is enabled for the bucket. If the returned value is false, the transfer acceleration feature is disabled for the bucket. 
result = bucket.get_bucket_transfer_acceleration()
enabled_text = result.enabled
print("Returns whether to enable transfer acceleration: ", enabled_text)

References

  • For more information about the complete sample code that is used to enable transfer acceleration for a bucket, visit GitHub.
  • For more information about the API operation that you can call to enable transfer acceleration for a bucket, see PutBucketTransferAcceleration.
  • For more information about the API operation that you can call to query the transfer acceleration status of a bucket, see GetBucketTransferAcceleration.