DataFlex
DataFlex
Bunny Edge Storage - List Files
See more Bunny CDN Examples
Retrieve a list of files and directories located in the given directory.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vSbResponse
Handle hoSbResponse
Integer iStatusCode
Handle hoJarr
Variant vJson
Handle hoJson
String sGuid
String sStorageZoneName
String sPath
String sObjectName
Integer iLength
String sLastChanged
Integer iServerId
Integer iArrayNumber
Boolean iIsDirectory
String sUserId
String sContentType
String sDateCreated
Integer iStorageZoneId
String sChecksum
String sReplicatedZones
Integer i
Integer iCount_i
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use the "Password" from the "FTP & HTTP API Access" console web page for your Bunny storage zone.
Send ComSetRequestHeader To hoHttp "AccessKey" "YOUR_FTP_AND_HTTP_PASSWORD"
// Storage Endpoints:
// The storage API endpoint depends on the primary storage region of your storage zone. You can also find this in the FTP & HTTP API Information of your storage zone.
// Falkenstein: storage.bunnycdn.com
// New York: ny.storage.bunnycdn.com
// Los Angeles: la.storage.bunnycdn.com
// Singapore: sg.storage.bunnycdn.com
// Sydney: syd.storage.bunnycdn.com
// London: uk.storage.bunnycdn.com
// ... (possibly others??)
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
If (Not(IsComObjectCreated(hoSbResponse))) Begin
Send CreateComObject of hoSbResponse
End
// Change the "storageZoneName" to your actual storage zone name.
Get pvComObject of hoSbResponse to vSbResponse
Get ComQuickGetSb Of hoHttp "https://uk.storage.bunnycdn.com/storageZoneName/testDir/" vSbResponse To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLastStatus Of hoHttp To iStatusCode
Showln "Status code = " iStatusCode
If (iStatusCode <> 200) Begin
Get ComGetAsString Of hoSbResponse To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonArray)) To hoJarr
If (Not(IsComObjectCreated(hoJarr))) Begin
Send CreateComObject of hoJarr
End
Get pvComObject of hoSbResponse to vSbResponse
Get ComLoadSb Of hoJarr vSbResponse To iSuccess
Set ComEmitCompact Of hoJarr To False
Get ComEmit Of hoJarr To sTemp1
Showln sTemp1
// Here is a sample response. Parsing code is shown below..
// [
// {
// "Guid": "ebd9ccff-faf7-449d-9c71-8662b9f3cf41",
// "StorageZoneName": "chilkat",
// "Path": "/chilkat/testDir/",
// "ObjectName": "seahorse.jpg",
// "Length": 24388,
// "LastChanged": "2023-04-21T15:59:08.382",
// "ServerId": 586,
// "ArrayNumber": 0,
// "IsDirectory": false,
// "UserId": "6d26ab35-2914-422c-9378-d51f38166e53",
// "ContentType": "",
// "DateCreated": "2023-04-21T15:59:08.382",
// "StorageZoneId": 266805,
// "Checksum": "0503558E7B4D141C067BEECFD06F87F6F58B81E37918310F82C7C4077D27BD1D",
// "ReplicatedZones": "SE,DE,LA,SG,JH,BR,SYD,NY"
// },
// {
// "Guid": "e74b85f8-4d5d-459e-a2fc-0fcfa8c926aa",
// "StorageZoneName": "chilkat",
// "Path": "/chilkat/testDir/",
// "ObjectName": "seal.jpg",
// "Length": 342708,
// "LastChanged": "2023-04-21T15:59:08.763",
// "ServerId": 586,
// "ArrayNumber": 2,
// "IsDirectory": false,
// "UserId": "6d26ab35-2914-422c-9378-d51f38166e53",
// "ContentType": "",
// "DateCreated": "2023-04-21T15:59:08.763",
// "StorageZoneId": 266805,
// "Checksum": "C95F946A0299CE39C20A072B3DC581446B2EE2D94CA93901B58604F4EFB8AAB5",
// "ReplicatedZones": "DE,SE,SG,LA,JH,BR,SYD,NY"
// },
// {
// "Guid": "ca80cdbd-c6cf-445d-b367-0b33de7ae65a",
// "StorageZoneName": "chilkat",
// "Path": "/chilkat/testDir/",
// "ObjectName": "university.jpg",
// "Length": 277581,
// "LastChanged": "2023-04-21T15:59:10.142",
// "ServerId": 586,
// "ArrayNumber": 0,
// "IsDirectory": false,
// "UserId": "6d26ab35-2914-422c-9378-d51f38166e53",
// "ContentType": "",
// "DateCreated": "2023-04-21T15:59:10.142",
// "StorageZoneId": 266805,
// "Checksum": "96A10EAA1B778C066739A6233206022DB219B67A8775401D7865F40E6DD83571",
// "ReplicatedZones": "DE,SE,SG,JH,BR,LA,SYD,NY"
// }
// ]
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
Move 0 To i
Get ComSize Of hoJarr To iCount_i
While (i < iCount_i)
Get ComObjectAt Of hoJarr i To vJson
If (IsComObject(vJson)) Begin
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
Set pvComObject Of hoJson To vJson
End
Get ComStringOf Of hoJson "Guid" To sGuid
Get ComStringOf Of hoJson "StorageZoneName" To sStorageZoneName
Get ComStringOf Of hoJson "Path" To sPath
Get ComStringOf Of hoJson "ObjectName" To sObjectName
Get ComIntOf Of hoJson "Length" To iLength
Get ComStringOf Of hoJson "LastChanged" To sLastChanged
Get ComIntOf Of hoJson "ServerId" To iServerId
Get ComIntOf Of hoJson "ArrayNumber" To iArrayNumber
Get ComBoolOf Of hoJson "IsDirectory" To iIsDirectory
Get ComStringOf Of hoJson "UserId" To sUserId
Get ComStringOf Of hoJson "ContentType" To sContentType
Get ComStringOf Of hoJson "DateCreated" To sDateCreated
Get ComIntOf Of hoJson "StorageZoneId" To iStorageZoneId
Get ComStringOf Of hoJson "Checksum" To sChecksum
Get ComStringOf Of hoJson "ReplicatedZones" To sReplicatedZones
Send Destroy of hoJson
Move (i + 1) To i
Loop
End_Procedure