当您不再需要保留某个桶(Bucket)时,可将其删除,以免产生额外费用。
删除桶之前,请确保您已经删除桶中所有数据。
以下代码用于删除存储桶。
using System; using TOS; using TOS.Error; using TOS.Model; namespace ConsoleApp { internal class Program { private static void Main(string[] args) { var ak = Environment.GetEnvironmentVariable("TOS_ACCESS_KEY"); var sk = Environment.GetEnvironmentVariable("TOS_SECRET_KEY"); // endpoint 若没有指定HTTP协议(HTTP/HTTPS),默认使用 HTTPS // Bucket 的 Endpoint,以华北2(北京)为例:https://tos-cn-beijing.volces.com var endpoint = "https://tos-cn-beijing.volces.com"; var region = "cn-beijing"; // 填写 BucketName var bucketName = "*** Provide your bucket name ***"; // 创建TOSClient实例 var client = TosClientBuilder.Builder().SetAk(ak).SetSk(sk).SetEndpoint(endpoint).SetRegion(region).Build(); try { // 创建删除桶输入 var deleteBucketInput = new DeleteBucketInput() { Bucket = bucketName, }; // 删除桶 var deleteBucketOutput = client.DeleteBucket(deleteBucketInput); // 桶存在,查看请求信息和桶信息 Console.WriteLine("Delete bucket succeeded, request id {0} ", deleteBucketOutput.RequestID); Console.WriteLine("Delete bucket succeeded, status code {0} ", deleteBucketOutput.StatusCode); } catch (TosServerException ex) { Console.WriteLine("Delete bucket failed, request id {0}", ex.RequestID); Console.WriteLine("Delete bucket failed, status code {0}", ex.StatusCode); Console.WriteLine("Delete bucket failed, response error code {0}", ex.Code); Console.WriteLine("Delete bucket failed, response error message {0}", ex.Message); } catch (TosClientException ex) { Console.WriteLine("Delete bucket failed, error message {0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Delete bucket failed, {0}", ex.Message); } } } }
关于删除桶的 API 接口详细介绍,请参见 DeleteBucket。