File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,6 +124,45 @@ int main() {
124124}
125125```
126126
127+ Delete a non-empty bucket:
128+
129+ ```cpp
130+ #include <s3cpp/s3.h>
131+
132+ int main() {
133+ S3Client client("minio_access", "minio_secret");
134+
135+ // To delete a bucket we first need to delete all its contents
136+ ListObjectsPaginator paginator(client, "my-bucket", "", 1000);
137+
138+ while (paginator.HasMorePages()) {
139+ auto page = paginator.NextPage();
140+
141+ if (!page) {
142+ std::println("Error listing objects: {}", page.error().Message);
143+ return 1;
144+ }
145+
146+ for (const auto& obj : page->Contents) {
147+ auto result = client.DeleteObject("my-bucket", obj.Key);
148+ if (!result) {
149+ std::println("Error deleting {}: {}", obj.Key, result.error().Message);
150+ return 1;
151+ }
152+ }
153+ }
154+
155+ auto result = client.DeleteBucket("my-bucket");
156+ if (!result) {
157+ std::println("Error deleting bucket: {}", result.error().Message);
158+ return 1;
159+ }
160+
161+ std::println("Bucket deleted successfully");
162+ return 0;
163+ }
164+ ```
165+
127166## Build and Test
128167
129168``` bash
You can’t perform that action at this time.
0 commit comments