private void PutBucketVersioning(bool enable) { try { PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //开启版本控制 request.IsEnableVersionConfig(enable); //执行请求 PutBucketVersioningResult result = cosXml.PutBucketVersioning(request); Assert.AreEqual(result.httpCode, 200); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.Fail(); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Fail(); } }
public static void PutBucketVersioning(COSXML.CosXml cosXml, string bucket) { try { PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //开启版本控制 request.IsEnableVersionConfig(true); //执行请求 PutBucketVersioningResult result = cosXml.PutBucketVersioning(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void AsynPutBucketVersioning(COSXML.CosXml cosXml, string bucket) { PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //开启版本控制 request.IsEnableVersionConfig(true); ///执行请求 cosXml.PutBucketVersioning(request, delegate(CosResult cosResult) { PutBucketVersioningResult result = cosResult as PutBucketVersioningResult; Console.WriteLine(result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public void putBucketVersioning() { //.cssg-snippet-body-start:[put-bucket-versioning] CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(true) //设置默认 HTTPS 请求 .SetAppid("1253653367") //设置腾讯云账户的账户标识 APPID .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域 .Build(); string secretId = Environment.GetEnvironmentVariable("COS_KEY"); //云 API 密钥 SecretId string secretKey = Environment.GetEnvironmentVariable("COS_SECRET"); //云 API 密钥 SecretKey long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); string bucket = "bucket-cssg-test-dotnet-1253653367"; //格式:BucketName-APPID PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); request.IsEnableVersionConfig(true); //true: 开启版本控制; false:暂停版本控制 // 使用同步方法 try { PutBucketVersioningResult result = cosXml.PutBucketVersioning(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx); Assert.Null(clientEx); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Null(serverEx); } //.cssg-snippet-body-end }
/// 设置存储桶多版本 public void PutBucketVersioning() { //.cssg-snippet-body-start:[put-bucket-versioning] string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); request.IsEnableVersionConfig(true); //true: 开启版本控制; false:暂停版本控制 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()); } //.cssg-snippet-body-end }