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

Warning Deleted buckets cannot be recovered. Exercise caution when you delete buckets.

Prerequisites

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

    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 that are uploaded 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.