If you no longer use a bucket, delete the bucket to stop unnecessary charges.

Warning Deleted buckets cannot be recovered. Exercise caution when you perform this operation.

Prerequisites

  • All objects in the bucket are deleted.
    • For more information about how to manually delete a small number of objects, see Delete objects.
    • If you want to delete a large number of objects, we recommend that you configure lifecycle rules to delete the objects in batches. For more information about how to delete a large number of objects, see Configure lifecycle rules.
    Notice

    If versioning is enabled for the bucket that you want to delete, make sure that all versions of objects in the bucket are deleted. For more information about how to delete all versions of objects in a bucket, see Configure versioning.

  • Parts generated by multipart upload or resumable upload tasks in the bucket are deleted. For more information about how to delete parts in a bucket, see Manage parts.
  • All LiveChannels in the bucket are deleted. For more information about how to delete LiveChannels, see DeleteLiveChannel.

Examples

The following code provides an example on how to delete a bucket named examplebucket:

OSSDeleteBucketRequest * delete = [OSSDeleteBucketRequest new];
// Specify the name of the bucket. Example: examplebucket. 
delete.bucketName = @"examplebucket";
OSSTask * deleteTask = [client deleteBucket:delete];
[deleteTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"delete bucket success!");
    } else {
        NSLog(@"delete bucket failed, error: %@", task.error);
    }
    return nil;
}];

References

  • For the complete sample code that is used to delete a bucket, visit GitHub.
  • For more information about the API operation that you can call to delete a bucket, see DeleteBucket.