By default, when you call the HeadObject operation on an object in a versioned bucket, only the metadata of the object of the current version is returned. You can obtain the metadata of an object of a specified version by specifying the version ID of the object.

Note If the current version of the object is a delete marker, Object Storage Service (OSS) returns 404 Not Found. If you specify a version ID in the request, OSS returns the metadata of the object of the specified version. For more information about how to obtain the version IDs of an object, see List objects.

The following code provides an example on how to obtain the metadata of the exampleobject.txt object of the specified version in the exampledir directory of the examplebucket bucket:

const OSS = require('ali-oss');

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the name of the bucket. Example: examplebucket. 
  bucket: 'examplebucket',
});

async function headInfo() {
  // Specify the full path of the object. Example: exampledir/exampleobject.txt. The full path of the object cannot contain bucket names. 
  const name = 'exampledir/exampleobject.txt'
  // Specify the version ID of the object to obtain the metadata of the object of the specified version. 
  const versionId = 'CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****'
  const options = {
    versionId
  };
  const result = client.head(name, options);
  console.log(result);
}

headInfo();

For more information about how to obtain object metadata , see HeadObject.