The transfer acceleration feature allows users worldwide to access objects stored in Object Storage Service (OSS) more quickly. This feature is applicable to 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.

Enable transfer acceleration

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

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. 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')
# Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set 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 state of a bucket

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

import oss2

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. 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')
# Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set 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 state 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 is called to enable transfer acceleration for a bucket, see PutBucketTransferAcceleration.
  • For more information about the API operation that is called to query the transfer acceleration state of a bucket, see GetBucketTransferAcceleration.