All Products
Search
Document Center

Object Storage Service:Use OSS SDK for iOS to query object metadata

Last Updated:May 29, 2024

You can call the HeadObject operation to obtain only the metadata instead of the content of an object.

Usage notes

  • Object metadata describes the attributes of an object. The metadata includes standard HTTP headers and user metadata. You can create custom HTTP request policies such as object cache policies and forced object download policies by configuring standard HTTP headers. You can configure user metadata for an object to identify the purposes or attributes of the object. For more information, see Manage object metadata.

  • You cannot use Object Storage Service (OSS) SDK for iOS to configure or modify object metadata.

Sample code

The following code provides an example on how to query object metadata:

OSSHeadObjectRequest * request = [OSSHeadObjectRequest new];
// Specify the bucket name. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Specify the full path of the object. Do not include the bucket name in the full path. 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 more information about the API operation that you can call to query object metadata, see GetObjectMeta.