tencent cloud

All product documents
Cloud Object Storage
Checking Whether an Object Exists
Last updated: 2024-01-23 17:15:08
Checking Whether an Object Exists
Last updated: 2024-01-23 17:15:08

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, HEAD Object returns object metadata. To view the SDK API that contains the full functionality of HEAD Object, please see Querying 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, please see SDK API Reference.

Querying Object Metadata

Description

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.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon