Visual FoxPro 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>'

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loXml
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"
loAuthAws.Region = "us-east-1"
loAuthAws.ServiceName = "s3"
loRest.SetAuthAws(loAuthAws)

*  URL: https://chilkat100.s3.amazonaws.com/starfish.jpg?tagging
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("chilkat100.s3.amazonaws.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

*  See the Online Tool for Generating XML Creation Code
loXml = CreateObject('Chilkat_9_5_0.Xml')
loXml.Tag = "Tagging"
loXml.UpdateChildContent("TagSet|Tag|Key","animal")
loXml.UpdateChildContent("TagSet|Tag|Value","starfish")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loXml.GetXmlSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("PUT","/starfish.jpg?tagging",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loXml
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
    ? "Response Status Code = " + STR(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loXml
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

RELEASE loRest
RELEASE loAuthAws
RELEASE loXml
RELEASE loSbRequestBody
RELEASE loSbResponseBody