Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Visual FoxPro Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Visual FoxPro) Amazon S3 List More than 1000 Objects in Bucket

S3 limits the size of the "List Objects" response to 1000 objects. To retrieve a listing of all of the objects in a bucket containing more than 1000 objects, we'll need to send several requests using continuation tokens.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loHttp
LOCAL loSbContinuationToken
LOCAL lnBGetMore
LOCAL loSbUri
LOCAL loXml
LOCAL lnSuccess
LOCAL lcItemKey
LOCAL lnItemSize
LOCAL lcLastModTimestamp
LOCAL loDt
LOCAL lcStrXml
LOCAL lnNumItems
LOCAL i
LOCAL lnBLocal
LOCAL loDtObj

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

loHttp = CreateObject('Chilkat_9_5_0.Http')

*  Insert your access key here:
loHttp.AwsAccessKey = "AWS_ACCESS_KEY"

*  Insert your secret key here:
loHttp.AwsSecretKey = "AWS_SECRET_KEY"

*  For the example, we'll get a listing containing approx. 25 objects
*  using continuation tokens with an artificially low max-keys set to 5.
*  (You may omit the max-keys query parameter to get the default 1000 maximum
*  number of keys per request.)

loSbContinuationToken = CreateObject('Chilkat_9_5_0.StringBuilder')
lnBGetMore = 1
loSbUri = CreateObject('Chilkat_9_5_0.StringBuilder')
loXml = CreateObject('Chilkat_9_5_0.Xml')

loDt = CreateObject('Chilkat_9_5_0.CkDateTime')

DO WHILE lnBGetMore = 1

    *  Make sure to set the "list-type" query param equal to "2".
    *  This chooses the GET Bucket (List Objects) Version 2 of the method.
    loSbUri.SetString("chilkat100?list-type=2&max-keys=5")
    IF (loSbContinuationToken.Length > 0) THEN
        loSbUri.Append("&continuation-token=")
        loSbUri.Append(loSbContinuationToken.GetEncoded("url","utf-8"))
    ENDIF

    lcStrXml = loHttp.S3_ListBucketObjects(loSbUri.GetAsString())
    IF (loHttp.LastMethodSuccess <> 1) THEN
        ? loHttp.LastErrorText
        RELEASE loHttp
        RELEASE loSbContinuationToken
        RELEASE loSbUri
        RELEASE loXml
        RELEASE loDt
        CANCEL
    ENDIF

    ? "Response status code = " + STR(loHttp.LastStatus)

    lnSuccess = loXml.LoadXml(lcStrXml)
    IF (lnSuccess <> 1) THEN
        ? loXml.LastErrorText
        RELEASE loHttp
        RELEASE loSbContinuationToken
        RELEASE loSbUri
        RELEASE loXml
        RELEASE loDt
        CANCEL
    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 (loHttp.LastStatus <> 200) THEN
        ? loXml.GetXml()
        ? "Failed."
        RELEASE loHttp
        RELEASE loSbContinuationToken
        RELEASE loSbUri
        RELEASE loXml
        RELEASE loDt
        CANCEL
    ENDIF

    *  If this is not the final response, then we'll get an XML response that begins
    *  like this.  (The IsTruncated child will be "true", and the NextContinuationToken
    *  will have a value to be used in the next request.)
    *  	<?xml version="1.0" encoding="UTF-8" ?>
    *  	<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    *  	    <Name>chilkat100</Name>
    *  	    <Prefix />
    *  	    <NextContinuationToken>1Mlcx+W9OKsr8cxp3DP6r71wgsTUMj0vqlntWoaJKNbYdrauLdf40LsUdBeSYGFhzbGIHdcf5DSLcEBWbqG+1fW1UcQkUW1V4qgQONAKOwb8y8vOLJAQ8iQ==</NextContinuationToken>
    *  	    <KeyCount>5</KeyCount>
    *  	    <MaxKeys>5</MaxKeys>
    *  	    <IsTruncated>true</IsTruncated>
    * 

    *  Iterate over the bucket items in this chunk get information for each..
    lnNumItems = loXml.NumChildrenHavingTag("Contents")
    ? "Number of bucket items = " + STR(lnNumItems)

    i = 0
    DO WHILE i < lnNumItems
        loXml.I = i

        lcItemKey = loXml.GetChildContent("Contents[i]|Key")
        lnItemSize = loXml.GetChildIntValue("Contents[i]|Size")
        lcLastModTimestamp = loXml.GetChildContent("Contents[i]|LastModified")

        loDt.SetFromRfc822(lcLastModTimestamp)
        *  Get a local date/time.
        lnBLocal = 1
        loDtObj = loDt.GetDtObj(lnBLocal)

        ? STR(i) + ": " + lcItemKey + ", " + STR(lnItemSize) + ", " + STR(loDtObj.Day) + "-" + STR(loDtObj.Month) + "-" + STR(loDtObj.Year) + ":" + STR(loDtObj.Hour) + ":" + STR(loDtObj.Minute)
        RELEASE loDtObj

        i = i + 1
    ENDDO

    *  Check IsTruncated.
    lnBGetMore = 0
    IF (loXml.ChildContentMatches("IsTruncated","true",1) = 1) THEN
        loSbContinuationToken.SetString(loXml.GetChildContent("NextContinuationToken"))
        IF (loSbContinuationToken.Length > 0) THEN
            lnBGetMore = 1
        ENDIF

    ENDIF

ENDDO

*  The output of this example (when tested) was:

*  Response status code = 200
*  Number of bucket items = 5
*  0: Abc.ics, 1833, 25-5-2011:9:53
*  1: Corpse Bride film poster.jpg, 53481, 6-9-2016:13:32
*  2: chiliPepper.gif, 7718, 12-3-2017:12:18
*  3: chilkatdude.jpg, 35137, 20-5-2011:16:14
*  4: cloud.search/dfe/indexer/pscc/2016/3/28/id,x-2-15-0-25-87-0.json, 1238, 2-4-2016:12:0
*  Response status code = 200
*  Number of bucket items = 5
*  0: cloud.search/dfe/indexer/pscc/2016/3/28/idx-2-15-0-25-87-0.json, 1238, 2-4-2016:11:33
*  1: dude.gif, 6373, 25-5-2011:17:29
*  2: french.txt, 47, 12-3-2017:12:18
*  3: hamlet.xml, 279658, 2-5-2016:12:21
*  4: hamlet_play.xml, 279658, 20-3-2017:8:22
*  Response status code = 200
*  Number of bucket items = 5
*  0: images/sea_creatures/starfish123.jpg, 6229, 19-1-2017:10:45
*  1: images/sea_creatures/starfishåäö.jpg, 6229, 19-1-2017:12:7
/
*  2: new folder/, 0, 26-11-2014:12:36
*  3: new_starfish.jpg, 6229, 20-3-2017:8:22
*  4: pigs.xml, 2804, 20-3-2017:8:22
*  Response status code = 200
*  Number of bucket items = 5
*  0: somethingBig.zip, 13089458, 26-9-2016:9:29
*  1: starfish.jpg, 6229, 12-3-2017:12:18
*  2: starfish/, 0, 10-11-2014:10:7
*  3: starfish/starfish.jpg, 6229, 10-11-2014:10:8
*  4: starfish/starfish2.jpg, 6229, 19-11-2014:10:36
*  Response status code = 200
*  Number of bucket items = 5
*  0: starfish/starfish3.jpg, 6229, 24-11-2014:14:33
*  1: starfish2.jpg, 5987, 20-4-2012:12:6
*  2: starfish3.jpg, 5987, 11-4-2012:7:10
*  3: starfishA.jpg, 6229, 10-5-2016:8:44
*  4: starfishCust.jpg, 6229, 12-11-2014:18:25
*  Response status code = 200
*  Number of bucket items = 1
*  0: xyz.ics, 1833, 25-5-2011:8:52
* 
* 

RELEASE loHttp
RELEASE loSbContinuationToken
RELEASE loSbUri
RELEASE loXml
RELEASE loDt


 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.