All Products
Search
Document Center

Object Storage Service:Determine whether an object exists (iOS SDK)

Last Updated:Sep 21, 2026

OSS SDK for iOS provides a convenient synchronous API to check whether a specific object exists in a bucket.

Notes

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

    Note

    The region of the bucket is determined by the endpoint specified for initialization.

Sample code

The following code provides an example on how to determine whether an object exists:

NSError * error = nil;
BOOL isExist = [client doesObjectExistInBucket:@"examplebucket" objectKey:@"file" error:&error];
if (!error) {
    if(isExist) {
        NSLog(@"File exists.");
    } else {
        NSLog(@"File not exists.");
    }
} else {
    NSLog(@"Error!");
}