Sample code for 30+ languages & platforms
Xbase++

Wasabi List Bucket Objects

See more Wasabi Examples

Demonstrates how to download and parse XML for the list of objects in a bucket.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cBucketName
LOCAL cStrXml
LOCAL oXml
LOCAL cKey
LOCAL cLastModified
LOCAL cETag
LOCAL cSizeDecimalStr
LOCAL cID
LOCAL cDisplayName
LOCAL cStorageClass
LOCAL cListBucketResult_xmlns
LOCAL cName
LOCAL nMaxKeys
LOCAL cIsTruncated
LOCAL i
LOCAL nCount_i

nSuccess := 0

//  This example assumes the Chilkat HTTP API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

//  Insert your access key here:
oHttp:AwsAccessKey := "access-key"

//  Insert your secret key here:
oHttp:AwsSecretKey := "secret-key"

//  Use the endpoint matching the bucket's region.
oHttp:AwsEndpoint := "s3.us-west-1.wasabisys.com"

cBucketName := "chilkattest"

cStrXml := oHttp:S3_ListBucketObjects(cBucketName)
IF (oHttp:LastMethodSuccess != 1)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

? "Response status code = " + Str(oHttp:LastStatus)

oXml := CreateObject("Chilkat.Xml")
nSuccess := oXml:LoadXml(cStrXml)
IF (nSuccess != 1)
    ? oXml:LastErrorText
    oHttp:destroy()
    oXml:destroy()
    RETURN
ENDIF

//  If the response status code was not 200, then the XML response is not a 
//  listing of objects, but instead contains error information.
IF (oHttp:LastStatus != 200)
    ? oXml:GetXml()
    ? "Failed."
    oHttp:destroy()
    oXml:destroy()
    RETURN
ENDIF

//  A sample response is shown below.
? oXml:GetXml()
? "----"

//  Use this online tool to generate parsing code from sample XML: 
//  Generate Parsing Code from XML

//  <?xml version="1.0" encoding="UTF-8"?>
//  <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
//      <Name>chilkattest</Name>
//      <Prefix/>
//      <Marker/>
//      <MaxKeys>1000</MaxKeys>
//      <IsTruncated>false</IsTruncated>
//      <Contents>
//          <Key>orchard.json</Key>
//          <LastModified>2021-10-27T22:58:49.000Z</LastModified>
//          <ETag>&quot;303fb46cf341094fef6274b7789cd6aa&quot;</ETag>
//          <Size>22</Size>
//          <Owner>
//              <ID>1039F31570DBC320E89D391632FCA06FE6D10CBB2ADBD0BF6439BB1DA0C3FAD6</ID>
//              <DisplayName>admin</DisplayName>
//          </Owner>
//          <StorageClass>STANDARD</StorageClass>
//      </Contents>
//      <Contents>
//          <Key>seahorse.jpg</Key>
//          <LastModified>2021-10-27T22:35:29.000Z</LastModified>
//          <ETag>&quot;a8551f0a5437f43a796fca7623ee9232&quot;</ETag>
//          <Size>24388</Size>
//          <Owner>
//              <ID>1039F31570DBC320E89D391632FCA06FE6D10CBB2ADBD0BF6439BB1DA0C3FAD6</ID>
//              <DisplayName>admin</DisplayName>
//          </Owner>
//          <StorageClass>STANDARD</StorageClass>
//      </Contents>
//      <Contents>
//          <Key>seahorse2.jpg</Key>
//          <LastModified>2021-10-27T22:03:51.000Z</LastModified>
//          <ETag>&quot;a8551f0a5437f43a796fca7623ee9232&quot;</ETag>
//          <Size>24388</Size>
//          <Owner>
//              <ID>1039F31570DBC320E89D391632FCA06FE6D10CBB2ADBD0BF6439BB1DA0C3FAD6</ID>
//              <DisplayName>admin</DisplayName>
//          </Owner>
//          <StorageClass>STANDARD</StorageClass>
//      </Contents>
//  </ListBucketResult>

cListBucketResult_xmlns := oXml:GetAttrValue("xmlns")
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")
    ? Str(i) + ": " + cKey
    i := i + 1
ENDDO

oHttp:destroy()
oXml:destroy()