All Products
Search
Document Center

Object Storage Service:Delete object tags (C++ SDK)

Last Updated:Mar 20, 2026

Use the OSS C++ SDK to remove all tags from an object by calling DeleteObjectTagging.

Prerequisites

Before you begin, make sure that you have:

  • The oss:DeleteObjectTagging permission on the target object. For more information, see Attach a custom policy to a RAM user

  • The OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables set with valid access credentials

Usage notes

  • The following example uses the public endpoint for the China (Hangzhou) region. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead. For more information, see Regions and endpoints.

  • The following example creates an OSSClient instance using an OSS endpoint. To create an OSSClient using a custom domain name or Security Token Service (STS), see Create an OSSClient instance.

Sample code

The following example deletes all tags from an object:

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

int main(void)
{
    /* Set the endpoint for the region where the bucket is located.
       For example, for the China (Hangzhou) region: https://oss-cn-hangzhou.aliyuncs.com */
    std::string Endpoint = "yourEndpoint";
    /* Set the region ID where the bucket is located.
       For example, for the China (Hangzhou) region: cn-hangzhou */
    std::string Region = "yourRegion";
    /* Specify the bucket name. Example: examplebucket */
    std::string BucketName = "examplebucket";
    /* Specify the full object path, excluding the bucket name.
       Example: exampledir/exampleobject.txt */
    std::string ObjectName = "exampledir/exampleobject.txt";

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

    ClientConfiguration conf;
    conf.signatureVersion = SignatureVersionType::V4;

    /* Load access credentials from environment variables. */
    auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
    OssClient client(Endpoint, credentialsProvider, conf);
    client.SetRegion(Region);

    /* Delete all tags from the object. */
    auto delTaggingOutcome = client.DeleteObjectTagging(DeleteObjectTaggingRequest(BucketName, ObjectName));

    if (!delTaggingOutcome.isSuccess()) {
        std::cout << "DeleteObjectTagging failed"
            << ", code: " << delTaggingOutcome.error().Code()
            << ", message: " << delTaggingOutcome.error().Message()
            << ", requestId: " << delTaggingOutcome.error().RequestId() << std::endl;
        return -1;
    }

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

What's next