Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) S3 Get Bucket Objects with CommonPrefixesDemonstrates how to get a list of bucket objects using the prefix and delimiter query params to get an XML result with CommonPrefixes.
integer li_rc oleobject loo_Http string ls_StrXml oleobject loo_Xml integer li_Success string ls_Prefix integer i integer li_Count_i // This example assumes the Chilkat HTTP API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // Insert your access key here: loo_Http.AwsAccessKey = "AWS_ACCESS_KEY" // Insert your secret key here: loo_Http.AwsSecretKey = "AWS_SECRET_KEY" // In this example, my bucket is "chilkat100". // It contains a number of folders, one of which is named "images". // I want to get a list of all sub-folders under the "images" folder ls_StrXml = loo_Http.S3_ListBucketObjects("chilkat100?prefix=images/&delimiter=/") if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Http return end if Write-Debug "Response status code = " + string(loo_Http.LastStatus) loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") li_Success = loo_Xml.LoadXml(ls_StrXml) if li_Success <> 1 then Write-Debug loo_Xml.LastErrorText destroy loo_Http destroy loo_Xml return end if // If the response status code was not 200, then the XML response is not a // listing of objects, but instead contains error information. if loo_Http.LastStatus <> 200 then Write-Debug loo_Xml.GetXml() Write-Debug "Failed." destroy loo_Http destroy loo_Xml return end if // A sample response is shown below. Write-Debug loo_Xml.GetXml() Write-Debug "----" // Here is the list of sub-folders (i.e. CommonPrefixes) // <?xml version="1.0" encoding="UTF-8"?> // <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> // <Name>chilkat100</Name> // <Prefix>images/</Prefix> // <Marker/> // <MaxKeys>1000</MaxKeys> // <Delimiter>/</Delimiter> // <IsTruncated>false</IsTruncated> // <CommonPrefixes> // <Prefix>images/africa/</Prefix> // </CommonPrefixes> // <CommonPrefixes> // <Prefix>images/sea_creatures/</Prefix> // </CommonPrefixes> // </ListBucketResult> // The XML can be parsed like this: i = 0 li_Count_i = loo_Xml.NumChildrenHavingTag("CommonPrefixes") do while i < li_Count_i loo_Xml.I = i ls_Prefix = loo_Xml.GetChildContent("CommonPrefixes[i]|Prefix") Write-Debug "Prefix = " + ls_Prefix i = i + 1 loop destroy loo_Http destroy loo_Xml |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.