Delete files (Swift SDK)
This topic describes how to use the OSS Swift software development kit (SDK) to delete a single file or multiple files.
Use the delete operation with caution. Deleted files cannot be recovered.
Notes
-
The sample code in this topic uses the China (Hangzhou) region ID
cn-hangzhouand its public endpoint. If you want to access OSS from other Alibaba Cloud products in the same region, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see Regions and endpoints. -
To delete files, you must have the
oss:DeleteObjectpermission. For more information, see Grant a custom access policy to a RAM user.
Sample code
FAQ
How can I confirm that a file is deleted after I use the Swift SDK to delete it?
When you use the OSSClient deleteObject method in the OSS Swift SDK to delete a single file, the operation is successful if no exception is thrown. To verify that the file is deleted, you can call the OSSClient doesObjectExist method. This method checks whether the specified file exists. If this method returns false, the file is deleted. For more information, see Determine whether a file exists (Swift SDK).
References
-
For complete sample code for deleting a single file, see the GitHub example delete_object.
-
For information about the API operation for deleting a single file, see DeleteObject.
-
For information about the API operation for deleting multiple files, see DeleteMultipleObjects.