This document provides an overview of APIs and SDK code samples related to versioning.
API | Operation | Description |
---|---|---|
PUT Bucket versioning | Setting versioning | Sets a versioning configuration for a bucket |
GET Bucket versioning | Querying versioning | Queries the versioning configuration of a bucket |
For the parameters and method descriptions of all the APIs in the SDK, see Api Documentation.
This API is used to set a versioning configuration for a specified bucket. Once enabled, versioning can only be suspended but not disabled.
String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket);
request.IsEnableVersionConfig(true); //true: enables versioning; false: suspends versioning
try
{
PutBucketVersioningResult result = cosXml.PutBucketVersioning(request);
Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
Note:
For the complete sample, go to GitHub.
This API is used to query the versioning configuration of a specified bucket.
String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket);
try
{
GetBucketVersioningResult result = cosXml.GetBucketVersioning(request);
// Bucket lifecycle configuration
VersioningConfiguration conf = result.versioningConfiguration;
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
Note:
For the complete sample, go to GitHub.
Was this page helpful?