The HeadObject method retrieves metadata from an object without returning the object itself.
Notes
Object metadata describes the properties of an object. Metadata includes standard HTTP headers and user-defined metadata. Configure standard HTTP headers to create custom HTTP request policies, such as object cache policies and forced download policies. Configure user-defined metadata for an object to identify its purpose or properties. For more information, see Object metadata.
The OSS SDK for iOS does not support configuring or modifying object metadata.
Sample code
The following code shows how to retrieve object metadata:
OSSHeadObjectRequest * request = [OSSHeadObjectRequest new];
// Specify the bucket name. For example, examplebucket.
request.bucketName = @"examplebucket";
// Specify the full path of the object. The full path cannot contain the bucket name. For example, exampledir/exampleobject.txt.
request.objectKey = @"exampledir/exampleobject.txt";
OSSTask * headTask = [client headObject:request];
[headTask continueWithBlock:^id(OSSTask *task) {
if (!task.error) {
NSLog(@"head object success!");
OSSHeadObjectResult * result = task.result;
NSLog(@"header fields: %@", result.httpResponseHeaderFields);
for (NSString * key in result.objectMeta) {
NSLog(@"ObjectMeta: %@ - %@", key, [result.objectMeta objectForKey:key]);
}
} else {
NSLog(@"head object failed, error: %@" ,task.error);
}
return nil;
}];References
For a description of the API operation to retrieve object metadata, see GetObjectMeta.