> For the complete documentation index, see [llms.txt](https://docs.4everland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.4everland.org/storage/bucket/bucket-api-s3-compatible/s3-tags-instructions.md).

# S3 Tags Instructions

### Introduction

When using the Bucket to store files, you can categorize the stored content using tags. Each tag is a key-value pair that you can add to a file when uploading it or add to already uploaded files. You can also query tags using the bucket and file name (Keyname). This method is compatible with AWS S3. For more detailed information about tags, please refer to [AWS S3 Tag](https://docs.aws.amazon.com/AmazonS3/latest/userguide/tagging-managing.html).

### Example

#### Uploading a file and adding tags

```Plain
func ExampleS3_PutObject() {
 svc := s3.New(session.New())
 input := &s3.PutObjectInput{
  Body:                 aws.ReadSeekCloser(strings.NewReader("filetoupload")),
  Bucket:               aws.String("examplebucket"),
  Key:                  aws.String("exampleobject"),
  Tagging:              aws.String("key1=value1&key2=value2"),
 }

 result, err := svc.PutObject(input)
 if err != nil {
  if aerr, ok := err.(awserr.Error); ok {
   switch aerr.Code() {
   default:
    fmt.Println(aerr.Error())
   }
  } else {
   // Print the error, cast err to awserr.Error to get the Code and
   // Message from an error.
   fmt.Println(err.Error())
  }
  return
 }

 fmt.Println(result)
}
```

#### Adding tags to existing files

```Plain
func ExampleS3_PutObjectTagging() {
    svc := s3.New(session.New())
    input := &s3.PutObjectTaggingInput{
       Bucket: aws.String("examplebucket"),
       Key:    aws.String("exampleobject"),
       Tagging: &s3.Tagging{
          TagSet: []*s3.Tag{
             {
                Key:   aws.String("Key3"),
                Value: aws.String("Value3"),
             },
             {
                Key:   aws.String("Key4"),
                Value: aws.String("Value4"),
             },
          },
       },
    }

    result, err := svc.PutObjectTagging(input)
    if err != nil {
       if aerr, ok := err.(awserr.Error); ok {
          switch aerr.Code() {
          default:
             fmt.Println(aerr.Error())
          }
       } else {
          // Print the error, cast err to awserr.Error to get the Code and
          // Message from an error.
          fmt.Println(err.Error())
       }
       return
    }

    fmt.Println(result)
}
```

#### Requesting the corresponding tag through the bucket and filename

```Plain
func ExampleS3_GetObjectTagging() {
    svc := s3.New(session.New())
    input := &s3.GetObjectTaggingInput{
       Bucket: aws.String("examplebucket"),
       Key:    aws.String("exampleobject"),
    }

    result, err := svc.GetObjectTagging(input)
    if err != nil {
       if aerr, ok := err.(awserr.Error); ok {
          switch aerr.Code() {
          default:
             fmt.Println(aerr.Error())
          }
       } else {
          // Print the error, cast err to awserr.Error to get the Code and
          // Message from an error.
          fmt.Println(err.Error())
       }
       return
    }

    fmt.Println(result)
}
```

### Field descriptions

**Container for the TagSet and Tag elements**

Tagging type：`map`

**A collection of a set of tags**

TagSet (required): `Array<map>`

**Name of the object key**

Key (required) type: `String`

**Value of the tag**

Value (required) type: `String`

{% hint style="info" %}
The key and value are case-sensitive. For more information about tag limitations, please refer to [User-Defined Tag Restrictions](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html).
{% endhint %}
