tencent cloud

masukan

Object Tagging

Terakhir diperbarui:2024-02-02 16:24:05

    Overview

    This document provides an overview of APIs and SDK code samples related to object tagging.
    API
    Operation
    Description
    Tagging an object
    Tags an uploaded object.
    Querying object tags
    Queries all tags of an object.
    Deleting object tags
    Deletes all tags of an object.

    Tagging an Object

    Description

    This API is used to tag an object.

    Method prototype

    public SetObjectTaggingResult setObjectTagging(SetObjectTaggingRequest setObjectTaggingRequest);

    Sample 1. Tagging an uploaded object

    String bucketName = "examplebucket-1250000000";
    String key = "exampletkey";
    List<Tag> tags = new LinkedList<>();
    tags.add(new Tag("tag1", "value1"));
    tags.add(new Tag("tag2", "value2"));
    ObjectTagging objectTagging = new ObjectTagging(tags);
    SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucketName, key, objectTagging);
    cosclient.setObjectTagging(setObjectTaggingRequest);

    Sample 2. Tagging an object when it is uploaded

    String bucketName = "examplebucket-1250000000";
    String key = "testfiles/testTagging.txt";
    InputStream is = new ByteArrayInputStream(new byte[]{'d', 'a', 't', 'a'});
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setHeader("x-cos-tagging", "tag1=value1&tag2=value2");
    cosclient.putObject(bucketName, key, is, objectMetadata);

    Parameter description

    Parameter
    Description
    Type
    setObjectTaggingRequest
    Object tagging request
    SetObjectTaggingRequest
    The request members are described as follows:
    Request Member
    Setting Method
    Description
    Type
    bucketName
    Via a constructor or the set method
    Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
    String
    Key
    Via a constructor or the set method
    Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
    String
    objectTagging
    Via a constructor or the set method
    Object tagging
    ObjectTagging
    ObjectTagging member description:
    Parameter
    Description
    Type
    tagSet
    Tags to add to the object
    List<Tag>
    Tag member description:
    Parameter
    Description
    Type
    key
    Tag key
    String
    value
    Tag value
    String

    Response description

    Success: No value is returned.
    Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.

    Querying Object Tags

    Description

    This API is used to query the existing tags of a specified object.

    Method prototype

    public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest);

    Sample request

    String bucketName = "exampletbucket-1250000000";
    String key = "exampletkey";
    GetObjectTaggingRequest getObjectTaggingRequest = new GetObjectTaggingRequest(bucketName, key);
    GetObjectTaggingResult getObjectTaggingResult = cosclient.getObjectTagging(getObjectTaggingRequest);
    List<Tag> resultTagSet = getObjectTaggingResult.getTagSet();
    System.out.println(resultTagSet.toString());

    Parameter description

    Parameter
    Description
    Type
    getObjectTaggingRequest
    Request to query the tags of an object
    GetObjectTaggingRequest
    The request members are described as follows:
    Request Member
    Setting Method
    Description
    Type
    bucketName
    Via a constructor or the set method
    Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
    String
    Key
    Via a constructor or the set method
    Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
    String

    Response description

    Success: GetObjectTaggingResult is returned, which includes the tag information of the object.
    Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.

    Deleting Object Tags

    Description

    This API is used to delete the existing tags of a specified object.

    Method prototype

    public DeleteObjectTaggingResult deleteObjectTagging(DeleteObjectTaggingRequest deleteObjectTaggingRequest);

    Sample request

    String bucketName = "examplebucket-1250000000";
    String key = "exampleobject";
    DeleteObjectTaggingRequest deleteObjectTaggingRequest = new DeleteObjectTaggingRequest(bucketName, key);
    cosclient.deleteObjectTagging(deleteObjectTaggingRequest);

    Parameter description

    Parameter
    Description
    Type
    deleteObjectTaggingRequest
    Request to delete the tags of an object
    DeleteObjectTaggingRequest
    The request members are described as follows:
    Request Member
    Setting Method
    Description
    Type
    bucketName
    Via a constructor or the set method
    Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
    String
    Key
    Via a constructor or the set method
    Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
    String

    Response description

    Success: No value is returned.
    Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24