All Products
Search
Document Center

Object Storage Service:Delete object tags (Node.js SDK)

Last Updated:Nov 29, 2025

You can delete unnecessary tags of an object based on your requirements. If versioning is enabled for a bucket that stores the object whose tags you want to delete, Object Storage Service (OSS) deletes the tags of the current version of the object by default. To delete the tags of a specified version of the object, you must specify the version ID of the object.

Delete object tags

If versioning is not enabled for the bucket that stores the object whose tags you want to delete, you can delete the tags of the object based on your requirements. If versioning is enabled for the bucket that stores the object whose tags you want to delete, OSS deletes the tags of the current version of the object by default.

The following code provides an example on how to delete the tags of the exampleobject.txt object in the exampledir directory of the examplebucket bucket:

const OSS = require('ali-oss')

const client = new OSS({
  // Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name. For example, examplebucket.
  bucket: 'examplebucket',
});

// Specify the full path of the object. For example, exampledir/exampleobject.txt. The full path cannot contain the bucket name.
const objectName = 'exampledir/exampleobject.txt'

// Delete the object tags.
async function deleteObjectTagging(objectName) {
  try {
    const result = await client.deleteObjectTagging(objectName);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

deleteObjectTagging(objectName)

Delete tags from a specific version of an object

If versioning is enabled for the bucket that stores the object whose tags you want to delete, you can delete the tags of a specified version of the object by specifying the version ID of the object.

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

Note

For more information about how to obtain the version ID, see List objects.

const OSS = require('ali-oss')

const client = new OSS({
  // Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name. For example, examplebucket.
  bucket: 'examplebucket',
});

// Specify the full path of the object. For example, exampledir/exampleobject.txt. The full path cannot contain the bucket name.
const objectName = 'exampledir/exampleobject.txt'
// Specify the version ID of the object.
const versionId = 'CAEQIRiBgMDqvPqA3BciIDJhMjE4MWZkN2ViYTRmYzJhZjkxMzk2YWM2NjJk****'

// Delete the object tags.
async function deleteObjectTagging(objectName) {
  try {
    const options = {
      versionId
    };
    const result = await client.deleteObjectTagging(objectName, options);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

deleteObjectTagging(objectName)

References

  • For the complete sample code used to delete object tags, see GitHub.

  • For more information about the API operation used to delete object tags, see DeleteObjectTagging.