API | 操作名 | 操作描述 |
删除单个对象 | 在存储桶中删除指定对象 | |
删除多个对象 | 在存储桶中批量删除对象 |
QCloudDeleteObjectRequest* deleteObjectRequest = [QCloudDeleteObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketdeleteObjectRequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"deleteObjectRequest.object = @"exampleobject";[deleteObjectRequest setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteObject:deleteObjectRequest];
let deleteObject = QCloudDeleteObjectRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketdeleteObject.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"deleteObject.object = "exampleobject";deleteObject.finishBlock = {(result,error)inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteObject(deleteObject);
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 单次返回的最大条目数量,默认1000request.maxKeys = 100;//要删除的目录名称:带'/'request.prefix = @"prefix";[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {if(!error){NSMutableArray *deleteInfosArr = [NSMutableArray array];for (QCloudBucketContents *content in result.contents) {QCloudDeleteMultipleObjectRequest *delteRequest = [QCloudDeleteMultipleObjectRequest new];delteRequest.bucket = request.bucket;QCloudDeleteObjectInfo *object = [QCloudDeleteObjectInfo new];object.key = content.key;[deleteInfosArr addObject:object];}QCloudDeleteInfo *deleteInfos = [QCloudDeleteInfo new];deleteInfos.objects = [deleteInfosArr copy];QCloudDeleteMultipleObjectRequest *delteRequest = [QCloudDeleteMultipleObjectRequest new];delteRequest.bucket = @"examplebucket-1250000000";delteRequest.deleteObjects = deleteInfos;[delteRequest setFinishBlock:^(QCloudDeleteResult *outputObject, NSError *error) {NSLog(@"outputObject = %@",outputObject);}];[[QCloudCOSXMLService defaultCOSXML] DeleteMultipleObject:delteRequest];}}];[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
let getBucketReq = QCloudGetBucketRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetBucketReq.bucket = "examplebucket-1250000000";// 单次返回的最大条目数量,默认1000getBucketReq.maxKeys = 100;//要删除的目录名称:带'/'getBucketReq.prefix = "dir/";getBucketReq.setFinish { (result, error) inif let result = result {let contents = result.contents;let infos = NSMutableArray.init();for content in contents {let info = QCloudDeleteObjectInfo.init();info.key = content.key;infos.add(info);}let mutipleDel = QCloudDeleteMultipleObjectRequest.init();// 要删除的文件集合let deleteInfos = QCloudDeleteInfo.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";deleteInfos.objects = infos as! [QCloudDeleteObjectInfo];// 布尔值,这个值决定了是否启动 Quiet 模式:// true:启动 Quiet 模式// false:启动 Verbose 模式// 默认值为 FalsedeleteInfos.quiet = false;// 封装了需要批量删除的多个对象的信息mutipleDel.deleteObjects = deleteInfos;mutipleDel.setFinish { (result, error) inif let result = result {let deleted = result.deletedObjectslet failed = result.deletedFailedObjects} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteMultipleObject(mutipleDel);} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
QCloudDeleteMultipleObjectRequest* delteRequest = [QCloudDeleteMultipleObjectRequest new];delteRequest.bucket = @"examplebucket-1250000000";// 要删除的单个文件QCloudDeleteObjectInfo* deletedObject0 = [QCloudDeleteObjectInfo new];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"deletedObject0.key = @"exampleobject";// 要删除的文件集合QCloudDeleteInfo* deleteInfo = [QCloudDeleteInfo new];// 布尔值,这个值决定了是否启动 Quiet 模式:// true:启动 Quiet 模式// false:启动 Verbose 模式// 默认值为 FalsedeleteInfo.quiet = NO;// 存放需要删除对象信息的数组deleteInfo.objects = @[deletedObject0];// 封装了需要批量删除的多个对象的信息delteRequest.deleteObjects = deleteInfo;[delteRequest setFinishBlock:^(QCloudDeleteResult* outputObject,NSError *error) {// 可以从 outputObject 中获取 response 中 etag 或者自定义头部等信息}];[[QCloudCOSXMLService defaultCOSXML] DeleteMultipleObject:delteRequest];
let mutipleDel = QCloudDeleteMultipleObjectRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";// 要删除的单个文件let info1 = QCloudDeleteObjectInfo.init();// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"info1.key = "exampleobject";let info2 = QCloudDeleteObjectInfo.init();// 要删除的文件集合let deleteInfos = QCloudDeleteInfo.init();// 存放需要删除对象信息的数组deleteInfos.objects = [info1,info2];// 布尔值,这个值决定了是否启动 Quiet 模式:// true:启动 Quiet 模式// false:启动 Verbose 模式// 默认值为 FalsedeleteInfos.quiet = false;// 封装了需要批量删除的多个对象的信息mutipleDel.deleteObjects = deleteInfos;mutipleDel.setFinish { (result, error) inif let result = result {let deleted = result.deletedObjectslet failed = result.deletedFailedObjects} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteMultipleObject(mutipleDel);
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 单次返回的最大条目数量,默认1000request.maxKeys = 100;//如果要删除指定前缀的文件:prefix为文件名前缀request.prefix = @"prefix";[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {if(!error){NSMutableArray *deleteInfosArr = [NSMutableArray array];for (QCloudBucketContents *content in result.contents) {QCloudDeleteMultipleObjectRequest *delteRequest = [QCloudDeleteMultipleObjectRequest new];delteRequest.bucket = request.bucket;QCloudDeleteObjectInfo *object = [QCloudDeleteObjectInfo new];object.key = content.key;[deleteInfosArr addObject:object];}QCloudDeleteInfo *deleteInfos = [QCloudDeleteInfo new];deleteInfos.objects = [deleteInfosArr copy];QCloudDeleteMultipleObjectRequest *delteRequest = [QCloudDeleteMultipleObjectRequest new];delteRequest.bucket = @"examplebucket-1250000000";delteRequest.deleteObjects = deleteInfos;[delteRequest setFinishBlock:^(QCloudDeleteResult *outputObject, NSError *error) {NSLog(@"outputObject = %@",outputObject);}];[[QCloudCOSXMLService defaultCOSXML] DeleteMultipleObject:delteRequest];}}];[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
let getBucketReq = QCloudGetBucketRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetBucketReq.bucket = "examplebucket-1250000000";// 单次返回的最大条目数量,默认1000getBucketReq.maxKeys = 100;//如果要删除指定前缀的文件:prefix为文件名前缀getBucketReq.prefix = "dir/";getBucketReq.setFinish { (result, error) inif let result = result {let contents = result.contents;let infos = NSMutableArray.init();for content in contents {let info = QCloudDeleteObjectInfo.init();info.key = content.key;infos.add(info);}let mutipleDel = QCloudDeleteMultipleObjectRequest.init();// 要删除的文件集合let deleteInfos = QCloudDeleteInfo.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";deleteInfos.objects = infos as! [QCloudDeleteObjectInfo];// 布尔值,这个值决定了是否启动 Quiet 模式:// true:启动 Quiet 模式// false:启动 Verbose 模式// 默认值为 FalsedeleteInfos.quiet = false;// 封装了需要批量删除的多个对象的信息mutipleDel.deleteObjects = deleteInfos;mutipleDel.setFinish { (result, error) inif let result = result {let deleted = result.deletedObjectslet failed = result.deletedFailedObjects} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteMultipleObject(mutipleDel);} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
本页内容是否解决了您的问题?