删除Object
更新时间:2022-10-21
基本流程
- 创建BOSClient类的实例。
- 执行BOSClient deleteObject方法。
- 若操作失败后产生错误。
示例代码
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
9 if (output.error) {
10 NSLog(@"delete obj failure");
11 }
12});
13[task waitUtilFinished];
完整示例
Swift
1#import <BaiduBCEBasic/BaiduBCEBasic.h>
2#import <BaiduBCEBOS/BaiduBCEBOS.h>
3
4void example(void) {
5 // 初始化
6 BCECredentials* credentials = [[BCECredentials alloc] init];
7 credentials.accessKey = @"<access key>";
8 credentials.secretKey = @"<secret key>";
9 BOSClientConfiguration* configuration = [[BOSClientConfiguration alloc] init];
10 configuration.credentials = credentials;
11
12 BOSClient* client = [[BOSClient alloc] initWithConfiguration:configuration];
13
14 __block BOSDeleteObjectResponse* response = nil;
15 BCETask* task = [client deleteObject:@"<bucketname>" objectKey:@"<objectname>"];
16 task.then(^(BCEOutput* output) {
17 if (output.response) {
18 response = (BOSDeleteObjectResponse*)output.response;
19 NSLog(@"delete obj success!");
20 }
21
22 if (output.error) {
23 NSLog(@"delete obj failure");
24 }
25 });
26 [task waitUtilFinished];
27}