Xbase++
Xbase++
S3 List Buckets (using Chilkat REST)
See more Amazon S3 (new) Examples
Demonstrates how to fetch a list of S3 buckets.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL oSbResponse
LOCAL nStatusCode
LOCAL oXml
LOCAL cName
LOCAL cCreationDate
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)
oSbResponse := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestNoBodySb("GET", "/", oSbResponse)
IF (nSuccess == 0)
? 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
i := 0
nCount_i := oXml:NumChildrenHavingTag("Buckets|Bucket")
DO WHILE i < nCount_i
oXml:I := i
cName := oXml:GetChildContent("Buckets|Bucket[i]|Name")
cCreationDate := oXml:GetChildContent("Buckets|Bucket[i]|CreationDate")
? cName
? cCreationDate
? "--"
i := i + 1
ENDDO
oRest:destroy()
oAuthAws:destroy()
oSbResponse:destroy()
oXml:destroy()