Object Tagging

Object tagging allows you to categorize objects using custom key-value pairs. This is useful for data lifecycle management and access control policies.

Setting Tags on a New Object

You can set tags during the initial upload via headers:

$options = [
    OssClient::OSS_HEADERS => [
        'x-oss-tagging' => 'category=finance&status=audit'
    ]
];
$ossClient->putObject($bucket, "report.pdf", $content, $options);

Managing Tags on Existing Objects

use OSS\Model\TaggingConfig;
use OSS\Model\Tag;

$config = new TaggingConfig();
$config->addTag(new Tag("Project", "Alpha"));
$config->addTag(new Tag("Owner", "DevTeam"));

$ossClient->putObjectTagging($bucket, "object.txt", $config);

Retrieving Tags

$config = $ossClient->getObjectTagging($bucket, "object.txt");
foreach ($config->getTags() as $tag) {
    echo $tag->getKey() . ": " . $tag->getValue() . PHP_EOL;
}

Deleting Tags

$ossClient->deleteObjectTagging($bucket, "object.txt");