This document provides an overview of APIs and SDK code samples related to versioning.
API | Operation | Description |
---|---|---|
PUT Bucket versioning | Setting versioning | Sets versioning for a bucket |
GET Bucket versioning | Querying versioning | Queries the versioning information of a bucket |
This API (PUT Bucket versioning) is used to set the versioning configuration for a bucket.
CosResult BucketOp::PutBucketVersioning(const PutBucketVersioningReq& req, PutBucketVersioningResp* resp);
qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::PutBucketVersioningReq req(bucket_name);
qcloud_cos::PutBucketVersioningResp resp;
// Enable versioning
req.SetStatus(true);
qcloud_cos::CosResult result = cos.PutBucketVersioning(req, &resp);
if (result.IsSucc()) {
// Request successful
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}
Parameter | Description | Type | Required |
---|---|---|---|
req | Request of the PutBucketVersioning operation |
PutBucketVersioningReq | Yes |
resp | Response of the PutBucketVersioning operation |
PutBucketVersioningResp | Yes |
PutBucketVersioningReq
provides the following method to enable/suspend versioning:
void SetStatus(bool is_enable);
This API is used to query the versioning configuration of a bucket.
CosResult CosAPI::GetBucketVersioning(const GetBucketVersioningReq& request, GetBucketVersioningResp* response);
qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::GetBucketVersioningReq req(bucket_name);
qcloud_cos::GetBucketVersioningResp resp;
qcloud_cos::CosResult result = cos.GetBucketVersioning(req, &resp);
if (result.IsSucc()) {
// Request successful. You can obtain the versioning status via the resp method.
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}
Parameter | Description | Type | Required |
---|---|---|---|
req | Request of the GetBucketVersioning operation |
GetBucketVersioningReq | Yes |
resp | Response of the GetBucketVersioning operation |
GetBucketVersioningResp | Yes |
GetBucketVersioningResp
provides the following method to obtain the status of versioning:
int GetStatus() const;
Was this page helpful?