Configures the versioning state of a specified bucket. Only the bucket owner can perform the PutBucketVersioning operation.

Note Versioning is not enabled for all buckets by default.

You can enable or suspend versioning for a bucket. When versioning is enabled for a bucket, each object uploaded to the bucket has a unique version ID, and different versions of the same object are all stored. When versioning is suspended, the version ID of all uploaded objects is null, and no more versions are stored for the objects of which the version ID is null.

Request syntax

PUT /?versioning HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
<?xml version="1.0" encoding="UTF-8"?>
<VersioningConfiguration>
    <Status>Enabled</Status>
<VersioningConfiguration>
Note
  • The versioning state of a bucket can only be set to Enabled or Suspended. Otherwise, the 400 Bad Request error is returned.
  • Versioning cannot be disabled after it is enabled for a bucket. However, you can suspend versioning to stop storing more object versions.

Examples

  • Enable versioning.
    Request example:
    PUT /?versioning HTTP/1.1
    Host: bucket-versioning.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 02:20:12 GMT
    Authorization: OSS e7thre3jj5mlvqk:12ztptkaR8a74gIGFzOaZZQe****
    <?xml version="1.0" encoding="UTF-8"?>
    <VersioningConfiguration>
        <Status>Enabled</Status>
    <VersioningConfiguration>
    Response example:
    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC015CB7AEADE01700****
    Date: Tue, 09 Apr 2019 02:20:12 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS
  • Suspend versioning.
    Request example:
    PUT /?versioning HTTP/1.1
    Host: bucket-versioning.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 02:28:18 GMT
    Authorization: OSS m2qa99e9tpkaehr:DWAzr2EkqDwFJNke1Nuaogn7****
    <?xml version="1.0" encoding="UTF-8"?>
    <VersioningConfiguration>
        <Status>Suspended</Status>
    <VersioningConfiguration>
    Response example:
    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC0342B7AEADE01700****
    Date: Tue, 09 Apr 2019 02:28:18 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS

Error code

Error code HTTP status code Description
AccessDenied 403 You do not have the permission to perform this operation. Only the bucket owner can initiate a PutBucketVersioning request.
InvalidArgument 400 The versioning state is invalid. The versioning state of a bucket can only be set to Enabled or Suspended.