Objective-C Google Cloud Storage: Delete Bucket

Back to Index

Permanently deletes an empty bucket. The path parameter is the name of the bucket to delete. In this example, we are deleting the bucket "chilkat-test-bucket". Success is indicated by a 204 response status code with an empty response body.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/buckets/delete

CURL Command

curl -X DELETE https://www.googleapis.com/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN"

Objective-C Example

#import <CkoRest.h>
#import <CkoStringBuilder.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://www.googleapis.com/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"www.googleapis.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest AddHeader: @"Authorization" value: @"Bearer CLOUD_STORAGE_TOKEN"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"DELETE" uriPath: @"/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
if (respStatusCode >= 400) {
    NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}