Delete Object
Updated at:2025-11-03
Basic workflow
- Instantiate the BOSClient class.
- Call the
eTagorlastModifiedmethod. - Handle errors that arise after an operation fails.
Example code
Swift
1__block BOSDeleteObjectResponse* response = nil;
2BCETask* task = [client deleteObject:@"<bucketname>" objectKey:@"<objectname>"];
3task.then(^(BCEOutput* output) {
4 if (output.response) {
5 response = (BOSDeleteObjectResponse*)output.response;
6 NSLog(@"delete obj success!");
7 }
8 if (output.error) {
9 NSLog(@"delete obj failure");
10 }
11});
12[task waitUtilFinished];
Complete example
Swift
1#import <BaiduBCEBasic/BaiduBCEBasic.h>
2#import <BaiduBCEBOS/BaiduBCEBOS.h>
3void example(void) {
4 // Initialize
5 BCECredentials* credentials = [[BCECredentials alloc] init];
6 credentials.accessKey = @"<access key>";
7 credentials.secretKey = @"<secret key>";
8 BOSClientConfiguration* configuration = [[BOSClientConfiguration alloc] init];
9 configuration.credentials = credentials;
10 BOSClient* client = [[BOSClient alloc] initWithConfiguration:configuration];
11 __block BOSDeleteObjectResponse* response = nil;
12 BCETask* task = [client deleteObject:@"<bucketname>" objectKey:@"<objectname>"];
13 task.then(^(BCEOutput* output) {
14 if (output.response) {
15 response = (BOSDeleteObjectResponse*)output.response;
16 NSLog(@"delete obj success!");
17 }
18 if (output.error) {
19 NSLog(@"delete obj failure");
20 }
21 });
22 [task waitUtilFinished];
23}
