Xbase++
Xbase++
S3 List Bucket Objects (Bucket-in-Path)
See more Amazon S3 (new) Examples
Demonstrates how to fetch a list of objects in an S3 bucket, but using the bucket-in-path request format instead of putting the bucket name in the HOST header.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL oSbResponse
LOCAL nStatusCode
LOCAL oXml
LOCAL cKey
LOCAL cLastModified
LOCAL cETag
LOCAL cSizeDecimalStr
LOCAL cID
LOCAL cDisplayName
LOCAL cStorageClass
LOCAL cName
LOCAL nMaxKeys
LOCAL cIsTruncated
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRest := CreateObject("Chilkat.Rest")
// Connect to the Amazon AWS REST server.
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("s3.amazonaws.com", nPort, nBTls, nBAutoReconnect)
// ----------------------------------------------------------------------------
// Important: For buckets created in regions outside us-east-1,
// there are three important changes that need to be made.
// See Working with S3 Buckets in Non-us-east-1 Regions for the details.
// ----------------------------------------------------------------------------
// Provide AWS credentials for the REST call.
oAuthAws := CreateObject("Chilkat.AuthAws")
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
oAuthAws:ServiceName := "s3"
nSuccess := oRest:SetAuthAws(oAuthAws)
// The bucket name is "chilkat100"
oSbResponse := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestNoBodySb("GET", "/chilkat100", oSbResponse)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
oAuthAws:destroy()
oSbResponse:destroy()
RETURN
ENDIF
nStatusCode := oRest:ResponseStatusCode
? "Response status code = " + Str(nStatusCode)
oXml := CreateObject("Chilkat.Xml")
oXml:LoadSb(oSbResponse, 1)
? oXml:GetXml()
IF (nStatusCode != 200)
? "Failed. See error information in the XML."
oRest:destroy()
oAuthAws:destroy()
oSbResponse:destroy()
oXml:destroy()
RETURN
ENDIF
// Use this online tool to generate code from sample XML:
// Generate Code to Create XML
cName := oXml:GetChildContent("Name")
nMaxKeys := oXml:GetChildIntValue("MaxKeys")
cIsTruncated := oXml:GetChildContent("IsTruncated")
i := 0
nCount_i := oXml:NumChildrenHavingTag("Contents")
DO WHILE i < nCount_i
oXml:I := i
cKey := oXml:GetChildContent("Contents[i]|Key")
cLastModified := oXml:GetChildContent("Contents[i]|LastModified")
cETag := oXml:GetChildContent("Contents[i]|ETag")
cSizeDecimalStr := oXml:GetChildContent("Contents[i]|Size")
cID := oXml:GetChildContent("Contents[i]|Owner|ID")
cDisplayName := oXml:GetChildContent("Contents[i]|Owner|DisplayName")
cStorageClass := oXml:GetChildContent("Contents[i]|StorageClass")
i := i + 1
ENDDO
? "Success."
oRest:destroy()
oAuthAws:destroy()
oSbResponse:destroy()
oXml:destroy()