You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Deleting a Bucket (.NET SDK)
Copy page
Download PDF
Deleting a Bucket (.NET SDK)
When you no longer need to retain a bucket (Bucket), you may delete it to avoid incurring additional charges.​
Prerequisites​
Before deleting a bucket, ensure that all data within the bucket has been removed.​
  • If versioning is enabled for the current bucket, please ensure that all current and historical version objects within the bucket have been deleted. For detailed instructions, see Delete Object.​
  • If there are unmerged shards in the bucket, please ensure that all shard data is deleted. For detailed instructions, please see Deleting Shards.​
  • If your bucket contains a large number of objects, you can configure batch deletion of objects by setting lifecycle rules. For instructions, see Configuring lifecycle rules.​
Notes​
  • Once a bucket is deleted, it cannot be restored. Please proceed with caution.​
  • Before deleting a bucket, you must ensure that your account has the tos:DeleteBucket permission. For detailed procedures, please refer to the Permission Configuration Guide.​
Sample Code​
The following code is used to delete a 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");​
var endpoint = "https://tos-cn-beijing.volces.com";​
var region = "cn-beijing";​
var bucketName = "*** Provide your bucket name ***";​
​
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);​
}​
}​
}​
}​
​
Related documentation​
For a detailed introduction to the API for deleting buckets, see DeleteBucket.​
Last updated: 2025.09.23 11:28:04