API | Operation | Description |
Deleting an object | Deletes an object from a bucket. | |
Deleting multiple objects | Deletes multiple objects from a bucket in a single request |
DELETE Object
) is used to delete a specified object.QCloudDeleteObjectRequest* deleteObjectRequest = [QCloudDeleteObjectRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketdeleteObjectRequest.bucket = @"examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"deleteObjectRequest.object = @"exampleobject";[deleteObjectRequest setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteObject:deleteObjectRequest];
let deleteObject = QCloudDeleteObjectRequest.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketdeleteObject.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"deleteObject.object = "exampleobject";deleteObject.finishBlock = {(result,error)inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteObject(deleteObject);
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000request.maxKeys = 100;// Name of the directory to delete, prefixed with a slash (/)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();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketgetBucketReq.bucket = "examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000getBucketReq.maxKeys = 100;// Name of the directory to delete, prefixed with a slash (/)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();// File set to be deletedlet deleteInfos = QCloudDeleteInfo.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";deleteInfos.objects = infos as! [QCloudDeleteObjectInfo];// Boolean value. Determines whether to enable the `Quiet` mode:// true: enable the `Quiet` mode// false: enable the `Verbose` mode// Default value: falsedeleteInfos.quiet = false;// Encapsulates the information on the multiple objects to be deleted in batchesmutipleDel.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";// Single file to be deletedQCloudDeleteObjectInfo* deletedObject0 = [QCloudDeleteObjectInfo new];// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"deletedObject0.key = @"exampleobject";// File set to be deletedQCloudDeleteInfo* deleteInfo = [QCloudDeleteInfo new];// Boolean value. Determines whether to enable the `Quiet` mode:// true: enable the `Quiet` mode// false: enable the `Verbose` mode// Default value: falsedeleteInfo.quiet = NO;// Array that stores the information on the objects to be deleteddeleteInfo.objects = @[deletedObject0];// Encapsulates the information on the multiple objects to be deleted in batchesdelteRequest.deleteObjects = deleteInfo;[delteRequest setFinishBlock:^(QCloudDeleteResult* outputObject,NSError *error) {// outputObject contains information such as the ETag or custom headers in the response.}];[[QCloudCOSXMLService defaultCOSXML] DeleteMultipleObject:delteRequest];
let mutipleDel = QCloudDeleteMultipleObjectRequest.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";// Single file to be deletedlet info1 = QCloudDeleteObjectInfo.init();// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"info1.key = "exampleobject";let info2 = QCloudDeleteObjectInfo.init();// File set to be deletedlet deleteInfos = QCloudDeleteInfo.init();// Array that stores the information on the objects to be deleteddeleteInfos.objects = [info1,info2];// Boolean value. Determines whether to enable the `Quiet` mode:// true: enable the `Quiet` mode// false: enable the `Verbose` mode// Default value: falsedeleteInfos.quiet = false;// Encapsulates the information on the multiple objects to be deleted in batchesmutipleDel.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];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000request.maxKeys = 100;//To delete files with a specified prefix, `prefix` should be the prefix of the files to deleterequest.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();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketgetBucketReq.bucket = "examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000getBucketReq.maxKeys = 100;//To delete files with a specified prefix, `prefix` should be the prefix of the files to deletegetBucketReq.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();// File set to be deletedlet deleteInfos = QCloudDeleteInfo.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketmutipleDel.bucket = "examplebucket-1250000000";deleteInfos.objects = infos as! [QCloudDeleteObjectInfo];// Boolean value. Determines whether to enable the `Quiet` mode:// true: enable the `Quiet` mode// false: enable the `Verbose` mode// Default value: falsedeleteInfos.quiet = false;// Encapsulates the information on the multiple objects to be deleted in batchesmutipleDel.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);
Was this page helpful?