By default, when you call the HeadObject operation on an object in a versioned bucket, only the metadata of the current version of the object is returned.

Note If the current version of the object is a delete marker, Object Storage Service (OSS) returns 404 Not Found. If you specify the version ID in the request, OSS returns the metadata of the specified version of the object.

Examples

The following code provides an example on how to query object metadata:
# -*- coding: utf-8 -*-
import oss2
# The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
# Specify the bucket name. Example: examplebucket. 
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# Add the versionId field to param. 
params = dict()
params['versionId'] = 'yourObjectVersionId'

# Query parts of the object metadata. 
simplifiedmeta = bucket.get_object_meta("yourObjectName", params=params)
print(simplifiedmeta.headers['Last-Modified'])
print(simplifiedmeta.headers['Content-Length'])
print(simplifiedmeta.headers['ETag'])

# Query all object metadata. 
objectmeta = bucket.head_object("yourObjectName", params=params)
print(objectmeta.headers['Content-Type'])
print(objectmeta.headers['Last-Modified'])
print(objectmeta.headers['x-oss-object-type'])

References

For more information about the API operations that you can call to query the metadata of an object, see HeadObject and GetObjectMeta.