All Products
Search
Document Center

Object Storage Service:Delete files (iOS SDK)

Last Updated:Jun 15, 2026

You can delete a single object or multiple objects at a time from an OSS bucket using the iOS SDK.

Warning

Deleted objects cannot be recovered. Exercise caution when you perform delete operations.

Usage notes

  • Before you run the sample code in this topic, you must create an OSSClient instance by using methods such as a custom domain name or Security Token Service (STS). For more information, see Initialization.

  • To delete an object, you must have write permissions on the bucket that stores the object.

Delete a single object

The following example shows how to delete an object named exampleobject.txt from a bucket named examplebucket:

OSSDeleteObjectRequest * delete = [OSSDeleteObjectRequest new];
// Specify the name of the bucket. Example: examplebucket.
delete.bucketName = @"examplebucket";
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampleobject.txt. 
delete.objectKey = @"exampleobject.txt";

OSSTask * deleteTask = [client deleteObject:delete];

[deleteTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        // ...
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [deleteTask waitUntilFinished];

Delete multiple objects at a time

You can delete up to 1,000 objects at a time.

Results can be returned in one of the following modes:

  • verbose: If quiet is set to NO, the list of all deleted objects is returned.

  • quiet: If quiet is not specified or is set to YES, only the list of objects that failed to be deleted is returned.

The following example shows how to delete multiple objects from a bucket named examplebucket and return the result in quiet mode:

OSSDeleteMultipleObjectsRequest *request = [OSSDeleteMultipleObjectsRequest new];
// Specify the name of the bucket. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Specify the full paths of objects to be deleted. Do not include the bucket name in the full paths of objects. 
request.keys = @[@"exampleobject.txt", @"testfolder/sampleobject.txt"];
// Set quiet to YES to return only a list of objects that failed to be deleted. 
request.quiet = YES;

OSSTask * deleteMultipleObjectsTask = [client deleteMultipleObjects:request];
[deleteMultipleObjectsTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        OSSDeleteMultipleObjectsResult *result = task.result;
        NSLog(@"delete objects: %@", result.deletedObjects);
    } else {
        NSLog(@"delete objects failed, error: %@", task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [deleteTask waitUntilFinished];

References

  • Delete a single object

    For the API operation used to delete a single object, see DeleteObject.

  • Delete multiple objects at a time

    For the API operation used to delete multiple objects, see DeleteMultipleObjects.

  • For more information about how to initialize an OSSClient instance, see Initialization.