The versioning state of a bucket applies to all objects in the bucket. If you enable versioning for a bucket, you can recover a previous version of an object in the bucket when you accidentally overwrite or delete the object.
Usage notes
-
The sample code in this topic uses the region ID
cn-hangzhouof the China (Hangzhou) region. By default, a public endpoint is used to access resources in a bucket. If you want to access resources in the bucket from other Alibaba Cloud services in the same region in which the bucket is located, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see Regions and endpoints. -
To set the versioning state of a bucket, you must have the
oss:PutBucketVersioningpermission. To obtain the versioning state of a bucket, you must have theoss:GetBucketVersioningpermission. For more information, see Grant a custom access policy to a RAM user.
Sample code
References
-
For the complete sample code to set the versioning state of a bucket, see put_bucket_version.py.
-
For the complete sample code to obtain the versioning state of a bucket, see get_bucket_cors.py.