Querying object metadata

Last updated: 2023-09-13 15:03:13

Feature Overview

This document provides an overview of APIs and SDK code samples for 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, see SDK API Reference.

Querying object metadata

Note

This API is used to query the metadata of an object.

Sample code

Objective-C
QCloudHeadObjectRequest* headerRequest = [QCloudHeadObjectRequest new];

// 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"
headerRequest.object = @"exampleobject";

// versionId specifies the version ID of an object to query (if versioning is enabled). If versionId is not specified, the latest version will be queried.
headerRequest.versionID = @"versionID";

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket
headerRequest.bucket = @"examplebucket-1250000000";

[headerRequest setFinishBlock:^(NSDictionary* result, NSError *error) {
// Detailed information returned in the result
// Obtain file CRC64
NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];
}];

[[QCloudCOSXMLService defaultCOSXML] HeadObject:headerRequest];
Note
For the complete sample, go to GitHub.
Swift
let headObject = QCloudHeadObjectRequest.init();

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket
headObject.bucket = "examplebucket-1250000000";

// versionId specifies the version ID of an object to query (if versioning is enabled). If versionId is not specified, the latest version will be queried.
headObject.versionID = "versionID";

// 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"
headObject.object = "exampleobject";
headObject.finishBlock = {(result,error) in
if let result = result {
// Obtain file CRC64
let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];

} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().headObject(headObject);
Note
For the complete sample, go to GitHub.