Excel AWS S3: Add a Set of Tags to an S3 Object

Back to Index

Adds a set of tags to an existing S3 object. This example adds tags to the object named "starfish.jpg" located in the bucket "chilkat100".

Documentation: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUTtagging.html

CURL Command

curl -X PUT https://chilkat100.s3.amazonaws.com/starfish.jpg?tagging \
  -d '<Tagging>
  <TagSet>
     <Tag>
       <Key>animal</Key>
       <Value>starfish</Value>
     </Tag>
  </TagSet>
</Tagging>'

Excel Example

Dim rest As Chilkat.Rest
Set rest = Chilkat.NewRest

Dim authAws As Chilkat.AuthAws
Set authAws = Chilkat.NewAuthAws
authAws.AccessKey = "AWS_ACCESS_KEY"
authAws.SecretKey = "AWS_SECRET_KEY"
authAws.Region = "us-east-1"
authAws.ServiceName = "s3"
success = rest.SetAuthAws(authAws)

'  URL: https://chilkat100.s3.amazonaws.com/starfish.jpg?tagging

bTls = True

port = 443

bAutoReconnect = True
success = rest.Connect("chilkat100.s3.amazonaws.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    Debug.Print "ConnectFailReason: "; rest.ConnectFailReason
    Debug.Print rest.LastErrorText
    Exit Sub
End If

'  See the Online Tool for Generating XML Creation Code
Dim xml As Chilkat.Xml
Set xml = Chilkat.NewXml
xml.Tag = "Tagging"
xml.UpdateChildContent "TagSet|Tag|Key","animal"
xml.UpdateChildContent "TagSet|Tag|Value","starfish"

Dim sbRequestBody As Chilkat.StringBuilder
Set sbRequestBody = Chilkat.NewStringBuilder
success = xml.GetXmlSb(sbRequestBody)
Dim sbResponseBody As Chilkat.StringBuilder
Set sbResponseBody = Chilkat.NewStringBuilder
success = rest.FullRequestSb("PUT","/starfish.jpg?tagging",sbRequestBody,sbResponseBody)
If (success <> True) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If


respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Status Code = "; respStatusCode
    Debug.Print "Response Header:"
    Debug.Print rest.ResponseHeader
    Debug.Print "Response Body:"
    Debug.Print sbResponseBody.GetAsString()
    Exit Sub
End If