Classic ASP 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

Classic ASP Example

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")

set authAws = Server.CreateObject("Chilkat_9_5_0.AuthAws")
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 = 1
port = 443
bAutoReconnect = 1
success = rest.Connect("chilkat100.s3.amazonaws.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "ConnectFailReason: " & rest.ConnectFailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

set sbResponseBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = rest.FullRequestNoBodySb("GET","/starfish.jpg?tagging",sbResponseBody)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Response Status Code = " & respStatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Header:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.ResponseHeader) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Body:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( sbResponseBody.GetAsString()) & "</pre>"

End If

set xmlResponse = Server.CreateObject("Chilkat_9_5_0.Xml")
success = xmlResponse.LoadSb(sbResponseBody,1)

'  See the Online Tool for Generating XML Parse Code

Tagging_xmlns = xmlResponse.GetAttrValue("xmlns")
i = 0
count_i = xmlResponse.NumChildrenHavingTag("TagSet|Tag")
Do While i < count_i
    xmlResponse.I = i
    Key = xmlResponse.GetChildContent("TagSet|Tag[i]|Key")
    Value = xmlResponse.GetChildContent("TagSet|Tag[i]|Value")
    i = i + 1
Loop

%>
</body>
</html>

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>