This document provides an overview of APIs and SDK code samples related to querying object metadata.
API | Operation | Description |
---|---|---|
HEAD Object | Querying object metadata | Queries the metadata of an object. |
For parameters and method description of all APIs in the SDK, please see SDK API Reference.
This API is used to query the metadata of an object.
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.intl.cloud.tencent.com/cos5/bucket
headerRequest.bucket = @"examplebucket-1250000000";
[headerRequest setFinishBlock:^(NSDictionary* result, NSError *error) {
// "result" contains the request result.
// Obtain the CRC64 value of the object.
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.intl.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 the CRC64 value of the object.
let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().headObject(headObject);
Note:For the complete sample, go to GitHub.
Was this page helpful?