AutoIt
AutoIt
Wasabi List Bucket Objects
See more Wasabi Examples
Demonstrates how to download and parse XML for the list of objects in a bucket.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat HTTP API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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"
Local $sBucketName = "chilkattest"
Local $strXml = $oHttp.S3_ListBucketObjects($sBucketName)
If ($oHttp.LastMethodSuccess <> True) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Response status code = " & $oHttp.LastStatus & @CRLF)
$oXml = ObjCreate("Chilkat.Xml")
$bSuccess = $oXml.LoadXml($strXml)
If ($bSuccess <> True) Then
ConsoleWrite($oXml.LastErrorText & @CRLF)
Exit
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) Then
ConsoleWrite($oXml.GetXml() & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; A sample response is shown below.
ConsoleWrite($oXml.GetXml() & @CRLF)
ConsoleWrite("----" & @CRLF)
; 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>"303fb46cf341094fef6274b7789cd6aa"</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>"a8551f0a5437f43a796fca7623ee9232"</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>"a8551f0a5437f43a796fca7623ee9232"</ETag>
; <Size>24388</Size>
; <Owner>
; <ID>1039F31570DBC320E89D391632FCA06FE6D10CBB2ADBD0BF6439BB1DA0C3FAD6</ID>
; <DisplayName>admin</DisplayName>
; </Owner>
; <StorageClass>STANDARD</StorageClass>
; </Contents>
; </ListBucketResult>
Local $sKey
Local $sLastModified
Local $sETag
Local $sSizeDecimalStr
Local $sID
Local $sDisplayName
Local $sStorageClass
Local $sListBucketResult_xmlns = $oXml.GetAttrValue("xmlns")
Local $sName = $oXml.GetChildContent("Name")
Local $iMaxKeys = $oXml.GetChildIntValue("MaxKeys")
Local $sIsTruncated = $oXml.GetChildContent("IsTruncated")
Local $i = 0
Local $iCount_i = $oXml.NumChildrenHavingTag("Contents")
While $i < $iCount_i
$oXml.I = $i
$sKey = $oXml.GetChildContent("Contents[i]|Key")
$sLastModified = $oXml.GetChildContent("Contents[i]|LastModified")
$sETag = $oXml.GetChildContent("Contents[i]|ETag")
$sSizeDecimalStr = $oXml.GetChildContent("Contents[i]|Size")
$sID = $oXml.GetChildContent("Contents[i]|Owner|ID")
$sDisplayName = $oXml.GetChildContent("Contents[i]|Owner|DisplayName")
$sStorageClass = $oXml.GetChildContent("Contents[i]|StorageClass")
ConsoleWrite($i & ": " & $sKey & @CRLF)
$i = $i + 1
Wend