A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to delete a bucket.
- Before you delete a bucket, you must delete all objects in the bucket, LiveChannel objects, and fragments generated by multipart uploads. For more information about deleting a LiveChannel object, see LiveChannel.
- To delete the fragments generated by multipart uploads, use Bucket.ListMultipartUploads to list all the fragments, and then use Bucket.AbortMultipartUpload to delete the fragments.
The following code provides an example on how to delete a bucket:
// This example uses the endpoint of the China (Hangzhou) region. Specify the actual endpoint based on your requirements. String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS, because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to https://ram.console.aliyun.com. String accessKeyId = "<yourAccessKeyId>"; String accessKeySecret = "<yourAccessKeySecret>"; // Create an OSSClient instance. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); // Delete the bucket. ossClient.deleteBucket("<yourBucketName>"); // Shut down the OSSClient instance. ossClient.shutdown();
For more information about how to delete a bucket, see DeleteBucket.