By default, calling the HeadObject operation on an object in a versioning-enabled bucket returns only metadata of the current version of the object.

Note If the current version of the object is a delete marker, OSS returns 404 Not Found. If you specify the version ID in your request, OSS returns metadata of the object with the specified version ID.

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

#include <alibabacloud/oss/OssClient.h>
#include <alibabacloud/oss/model/ObjectMetaData.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /*Initialize the OSS account information.*/
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";
    std::string BucketName = "yourBucketName";
    std::string ObjectName = "yourObjectName";

    /*Initialize network resources.*/
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

    /*Obtain some metadata of the object.*/
    GetObjectMetaRequest request(BucketName, ObjectName);
    request.setVersionId("yourObjectVersionId");
    auto outcome = client.GetObjectMeta(request);

    if (! outcome.isSuccess()) {
            /*Handle exceptions.*/
            std::cout << "GetObjectMeta fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
            ShutdownSdk();
            return -1;
    }
    else { 
            auto metadata = outcome.result();
            std::cout << " get metadata success, VersionId:" << metadata.VersionId() << std::endl;
    }

    /*Obtain all metadata of the object.*/
    HeadObjectRequest request1(BucketName, ObjectName);
    request1.setVersionId("yourObjectVersionId");
    outcome = client.HeadObject(request1);

    if (! outcome.isSuccess()) {
            /*Handle exceptions.*/
            std::cout << "HeadObject fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
ShutdownSdk();
            return -1;
    }
    else { 
            auto headMeta = outcome.result();
            std::cout << " get headMeta success, VersionId:" << headMeta.VersionId() << std::endl;
    }

    /*Release network resources.*/
    ShutdownSdk();
    return 0;
}

For more information about obtaining object metadata, see HeadObject and GetObjectMeta.