API | 操作名 | 操作描述 |
删除存储桶 | 删除指定账号下的空存储桶 |
using COSXML.Model.Bucket;using COSXML.Auth;using System;using COSXML;namespace COSSnippet{public class DeleteBucketModel {private CosXml cosXml;DeleteBucketModel() {CosXmlConfig config = new CosXmlConfig.Builder().SetRegion("COS_REGION") // 设置默认的区域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.Build();string secretId = "SECRET_ID"; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capistring secretKey = "SECRET_KEY"; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capilong durationSecond = 600; //每次请求签名有效时长,单位为秒QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}/// 删除存储桶public void DeleteBucket(){//.cssg-snippet-body-start:[delete-bucket]try{// 存储桶名称,此处填入格式必须为 BucketName-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";DeleteBucketRequest request = new DeleteBucketRequest(bucket);//执行请求DeleteBucketResult result = cosXml.DeleteBucket(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}// .cssg-methods-pragmastatic void Main(string[] args){DeleteBucketModel m = new DeleteBucketModel();/// 删除存储桶m.DeleteBucket();// .cssg-methods-pragma}}}
本页内容是否解决了您的问题?