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.
ImportantIf 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.
Sample code
The following code provides an example on how to delete a bucket:
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest("bucketName");
// Delete the bucket asynchronously.
OSSAsyncTask deleteBucketTask = oss.asyncDeleteBucket(deleteBucketRequest, new OSSCompletedCallback<DeleteBucketRequest, DeleteBucketResult>() {
@Override
public void onSuccess(DeleteBucketRequest request, DeleteBucketResult result) {
Log.d("asyncDeleteBucket", "Success!");
}
@Override
public void onFailure(DeleteBucketRequest request, ClientException clientException, ServiceException serviceException) {
// Handle request exceptions.
if (clientException != null) {
// Handle client exceptions, such as network exceptions.
clientException.printStackTrace();
}
if (serviceException != null) {
// Handle service exceptions.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
References
- For more information about 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.