Tous les produits
Search
Centre de documentation

Object Storage Service:Transfer acceleration (OSS SDK for Python 1.0)

Dernière mise à jour :Aug 18, 2026

L'accélération du transfert optimise l'accès mondial à OSS, ce qui est idéal pour les transferts de données sur de longues distances et le chargement ou le téléchargement d'objets volumineux (à l'échelle du Go ou du To).

Notes

  • Cette rubrique utilise le point de terminaison public de la région Chine (Hangzhou). Si vous souhaitez accéder à OSS depuis d'autres services Alibaba Cloud situés dans la même région, utilisez un point de terminaison interne. Pour plus d'informations sur les régions et les points de terminaison OSS, consultez Régions et points de terminaison.

  • Cette rubrique explique comment créer une instance OSSClient avec un point de terminaison OSS. Pour d'autres configurations, telles que l'utilisation d'un domaine personnalisé ou l'authentification via des identifiants du Security Token Service (STS), consultez Initialisation.

Activer l'accélération du transfert

L'exemple de code suivant montre comment activer l'accélération du transfert pour un bucket nommé examplebucket :

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# 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. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# 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)

Interroger le statut d'accélération du transfert d'un bucket

L'exemple de code suivant montre comment interroger le statut d'accélération du transfert d'un bucket nommé examplebucket :

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# 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. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# 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)

Références

  • Pour consulter l'exemple de code complet permettant d'activer l'accélération du transfert d'un bucket, rendez-vous sur GitHub.

  • Pour plus d'informations sur l'opération API permettant d'activer l'accélération du transfert, consultez PutBucketTransferAcceleration.

  • Pour plus d'informations sur l'opération API permettant d'interroger le statut d'accélération du transfert d'un bucket, consultez GetBucketTransferAcceleration.