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:

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

const client = new OSS({
  bucket: '<Your BucketName>',
  // The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
  region: '<Your Region>',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>'
});

async function headInfo() {
  const name = '<your objectName>'
  const versionId = 'your versionId' // Obtain the metadata of the object with the specified version ID.
  const options = {
    versionId
  };
  const result = client.head(name, options);
  console.log(result);
}

headInfo();

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