Setting Versioning

Last Updated At: 2025-10-21 09:10:00

Description

The PUT Bucket versioning API enables or pauses versioning for a bucket.

Notes

  1. If you have never enabled versioning on the bucket, the GET Bucket versioning request does not return a version status value.
  2. After enabling versioning, it can only be suspended, not closed.
  3. Setting the versioning status value to Enabled or Suspended indicates enabling or suspending versioning.
  4. To set the versioning feature for a bucket, you need write permission for the bucket.

Request

Request Example

PUT /?versioning HTTP 1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT date
Authorization: Auth String

Note:

Authorization: Auth String (For details, see Request Signature documentation).

Request Header

Common Headers

This request uses common request headers. For details, see Public Request Headers.

Non-common Headers

This request has no special request header information.

Request Body

<VersioningConfiguration>
  <Status></Status>
</VersioningConfiguration>

The data are as follows:

Node Name (Keyword) Parent Node Description Type
VersioningConfiguration No Specify the details of versioning. Container
Status VersioningConfiguration Specify whether the versioning is enabled, enumerated values: Suspended, Enabled. Enum

Response

Response Headers

Common Response Headers

This response uses common response headers. For details, see Common Response Headers.

Special Response Headers

There are no special response headers for this response operation.

Response Body

The response body is empty.

Error Analysis

The following table describes some special and common errors that may occur with this request. For details on error codes related to COS or the complete list of errors for the product, see Error Codes.

Error Code HTTP Status Code Description
InvalidArgument 400 Bad Request If the XML body is empty when versioning is enabled, it will return InvalidArgument.
InvalidDigest 400 Bad Request 1. The Content-MD5 carried is inconsistent with the request body calculated by the server.
1. There are only two valid values for the state of versioning: Enabled and Suspended. If any other state is specified, it will return InvalidArgument.

Practical Case

Request

PUT /?versioning HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.12.4
Content-Type: application/xml
Authorization: q-sign-algorithm=sha1&q-ak=AKID15IsskiBQKTZbAo6WhgcBqVls9Sm****&q-sign-time=1480932292;1981012292&q-key-time=1480932292;1981012292&q-url-param-list=versioning&q-header-list=host&q-signature=47ec2b80c73788ecd394d3b9ad90e120a32f****
Content-Length: 83

<VersioningConfiguration>
    <Status>Enabled</Status>
</VersioningConfiguration>

Response

HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Connection: keep-alive
Date: Wed, 23 Aug 2017 08:14:53 GMT
x-cos-request-id: NTk5ZDM5N2RfMjNiMjM1MGFfMmRiX2Y0****