Visual FoxPro AWS S3: Get S3 Object Tags

Back to Index

Returns the tags associated with an object. This example gets the tags for the object named "starfish.jpg" located in the bucket "chilkat100".

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

CURL Command

curl -X GET https://chilkat100.s3.amazonaws.com/starfish.jpg?tagging

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loXmlResponse
LOCAL lcTagging_xmlns
LOCAL i
LOCAL lnCount_i
LOCAL lcTagPath
LOCAL lcKey
LOCAL lcValue

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

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/starfish.jpg?tagging",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    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 loSbResponseBody
    CANCEL
ENDIF

loXmlResponse = CreateObject('Chilkat_9_5_0.Xml')
loXmlResponse.LoadSb(loSbResponseBody,1)

*  See the Online Tool for Generating XML Parse Code

lcTagging_xmlns = loXmlResponse.GetAttrValue("xmlns")
i = 0
lnCount_i = loXmlResponse.NumChildrenHavingTag("TagSet|Tag")
DO WHILE i < lnCount_i
    loXmlResponse.I = i
    lcKey = loXmlResponse.GetChildContent("TagSet|Tag[i]|Key")
    lcValue = loXmlResponse.GetChildContent("TagSet|Tag[i]|Value")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loAuthAws
RELEASE loSbResponseBody
RELEASE loXmlResponse

Sample XML Response Body

<?xml version="1.0" encoding="UTF-8" ?>
<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <TagSet>
        <Tag>
            <Key>habitat</Key>
            <Value>ocean</Value>
        </Tag>
        <Tag>
            <Key>phylum</Key>
            <Value>Echinodermata</Value>
        </Tag>
        <Tag>
            <Key>animal</Key>
            <Value>starfish</Value>
        </Tag>
    </TagSet>
</Tagging>