Version control applies to all objects in the bucket. By enabling version control for the bucket, you can restore objects to any previous version after accidental deletion or overwriting. Currently, multi-version support includes interfaces such as GetObject, GetObjectACL, CopyObject, UploadPartCopy, and DeleteObject. When calling these interfaces, you can specify the target object's specific version through the optional parameter version_id.
Bucket multi-version management
In TOS, a bucket's version status includes three states: disabled, versioning enabled, and versioning suspended.
warning
- To enable or suspend multi-version status for a bucket, your account must have the tos:PutBucketVersioning permission.
- To query the multi-version status of a bucket, your account must have the tos:GetBucketVersioning permission.
Set bucket version control status
The following code sets the bucket status to enable versioning or suspend version control.
Get the bucket version control status
The following code retrieves the version control status of the bucket bucket-test.
Download versioned object
The following code downloads a specified version of the object object-test from the bucket bucket-test into memory.
Delete versioned object
The following code deletes a specified version of the object object-test in the specified bucket bucket-test.
Empty a bucket with versioning enabled
The following code example empties an entire bucket with versioning enabled, including deleting multiple versions of objects, delete marker objects, and all uncommitted objects.