The HeadObject method can obtain only the object metadata but not the content of the object.
Note
- The object metadata includes HTTP headers and user metadata. For more information, see Manage object metadata in OSS Developer Guide.
- You cannot set or modify the object metadata by using the iOS SDK.
The following code provides an example on how to obtain the object metadata:
OSSHeadObjectRequest * request = [OSSHeadObjectRequest new];
request.bucketName = @"<bucketName>;
//objectKey indicates the name of the object, that is, the complete path of the object. objectKey must include the file extension of the object. For example, set objectKey to abc/efg/123.jpg.
request.objectKey = @"<objectKey>";
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;
}];