Checking whether an object exists

Last updated: 2023-09-13 15:02:33

Feature Overview

This document provides an overview of the API and sample code for quickly checking whether an object exists in a bucket. The sample code actually calls the HEAD Object COS API and is a simplified version of the API.
In addition to checking whether an object exists, the primary function of HEAD Object is to return object metadata. To view the SDK interface with the complete functionality of HEAD Object, please refer to Query Object Metadata.
API
Operation
Description
Querying object metadata
Queries the metadata of an object

SDK API References

For parameters and method description of all APIs in the SDK, see SDK API Reference.

Querying object metadata

Note

This API is used to check whether an object exists in a bucket.

Sample code

Objective-C

// Bucket name in the format of BucketName-APPID
NSString *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"
NSString *object = @"exampleobject";
[[QCloudCOSXMLService defaultCOSXML] doesObjectExistWithBucket:bucket object:object];
Note
For the complete sample, go to GitHub.
Swift
// Bucket name in the format of BucketName-APPID
let 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"
let object = "exampleobject";

QCloudCOSXMLService.defaultCOSXML().doesObjectExist(withBucket: bucket, object: object);

Note
For the complete sample, go to GitHub.