Delete bucket
Updated at:2025-11-03
Delete bucket
The following code can be used to delete a bucket:
C++
1int deleteBucket (Client& client, const std::string& bucketName) {
2 // Delete bucket
3 DeleteBucketRequest request(bucketName);
4 DeleteBucketResponse response;
5 int ret = client.delete_bucket(request, &response);
6 if (response.is_fail()) {
7 printf("error-message:%s\n", listBucketsResponse.error().message().c_str());
8 }
9 return ret;
10}
Note:
- Before deletion, ensure that all objects and any unfinished multipart uploads in the bucket have been fully removed. Otherwise, the deletion will fail.
- Before deleting a bucket, verify that Cross-Region Replication (CRR) is not enabled for the bucket, and that it is neither the source nor target bucket in any CRR rules. Otherwise, the deletion will fail.
