删除Object
更新时间:2022-10-21
基本流程
- 创建BOSClient类的实例。
- 执行BOSClient deleteObject方法。
- 若操作失败后产生错误。
示例代码
__block BOSDeleteObjectResponse* response = nil;
BCETask* task = [client deleteObject:@"<bucketname>" objectKey:@"<objectname>"];
task.then(^(BCEOutput* output) {
if (output.response) {
response = (BOSDeleteObjectResponse*)output.response;
NSLog(@"delete obj success!");
}
if (output.error) {
NSLog(@"delete obj failure");
}
});
[task waitUtilFinished];
完整示例
#import <BaiduBCEBasic/BaiduBCEBasic.h>
#import <BaiduBCEBOS/BaiduBCEBOS.h>
void example(void) {
// 初始化
BCECredentials* credentials = [[BCECredentials alloc] init];
credentials.accessKey = @"<access key>";
credentials.secretKey = @"<secret key>";
BOSClientConfiguration* configuration = [[BOSClientConfiguration alloc] init];
configuration.credentials = credentials;
BOSClient* client = [[BOSClient alloc] initWithConfiguration:configuration];
__block BOSDeleteObjectResponse* response = nil;
BCETask* task = [client deleteObject:@"<bucketname>" objectKey:@"<objectname>"];
task.then(^(BCEOutput* output) {
if (output.response) {
response = (BOSDeleteObjectResponse*)output.response;
NSLog(@"delete obj success!");
}
if (output.error) {
NSLog(@"delete obj failure");
}
});
[task waitUtilFinished];
}