Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C) S3 List Objects in Bucket Folder

See more Amazon S3 Examples

Demonstrates how to retrieve the XML listing of the objects (i.e. files) stored in an Amazon S3 bucket, but just within a particular folder.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkXml.h>
#include <C_CkDateTime.h>
#include <C_CkDtObj.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    const char *strXml;
    HCkXml xml;
    BOOL success;
    int numItems;
    const char *itemKey;
    const char *itemSizeDecimalStr;
    const char *lastModTimestamp;
    HCkDateTime dt;
    int i;
    BOOL bLocal;
    HCkDtObj dtObj;

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

    // In Amazon S3 (Simple Storage Service), there is a distinction between buckets and folders,
    // which are both used for organizing and storing data.

    // Bucket: A bucket is the top-level container in Amazon S3. It is similar to a directory or folder
    // at the root level and acts as a unique namespace for your objects (files). Each bucket must have a globally
    // unique name across all of Amazon S3. Buckets are created at the AWS account level and are used to store objects.

    // Folder (Prefix): In Amazon S3, folders are not actual physical entities but are virtual constructs called prefixes.
    // They are part of the object keys used to organize and group objects within a bucket. Object keys are essentially the
    // full path or name of an object, including the folder structure. For example, if you have an object named
    // "my-image.jpg" inside a folder named "photos," the object key would be "photos/my-image.jpg."
    // Folders are helpful for organizing objects within a bucket and creating a hierarchical structure.

    // In reality, S3 does not have a true folder structure. It stores objects in a flat structure with unique keys.
    // However, the keys can include slashes ("/") to create a visual separation that resembles a folder structure.
    // Various tools and S3 clients interpret the slashes as folder separators and display them accordingly.

    http = CkHttp_Create();

    // Insert your access key here:
    CkHttp_putAwsAccessKey(http,"AWS_ACCESS_KEY");

    // Insert your secret key here:
    CkHttp_putAwsSecretKey(http,"AWS_SECRET_KEY");

    // ----------------------------------------------------------------------------------
    // List the objects having prefix "images/"
    // ----------------------------------------------------------------------------------
    strXml = CkHttp_s3_ListBucketObjects(http,"chilkat100?prefix=images/");
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    printf("Response status code = %d\n",CkHttp_getLastStatus(http));

    xml = CkXml_Create();
    success = CkXml_LoadXml(xml,strXml);
    if (success != TRUE) {
        printf("%s\n",CkXml_lastErrorText(xml));
        CkHttp_Dispose(http);
        CkXml_Dispose(xml);
        return;
    }

    // If the response status code was not 200, then the XML response is not a 
    // listing of objects, but instead contains error information.
    if (CkHttp_getLastStatus(http) != 200) {
        printf("%s\n",CkXml_getXml(xml));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkXml_Dispose(xml);
        return;
    }

    // A sample response is shown below.
    printf("%s\n",CkXml_getXml(xml));
    printf("----\n");

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

    // Iterate over the bucket items and get information for each..
    numItems = CkXml_NumChildrenHavingTag(xml,"Contents");
    printf("Number of bucket items = %d\n",numItems);

    dt = CkDateTime_Create();

    i = 0;
    while (i < numItems) {
        CkXml_putI(xml,i);

        itemKey = CkXml_getChildContent(xml,"Contents[i]|Key");
        itemSizeDecimalStr = CkXml_getChildContent(xml,"Contents[i]|Size");
        lastModTimestamp = CkXml_getChildContent(xml,"Contents[i]|LastModified");

        CkDateTime_SetFromRfc822(dt,lastModTimestamp);
        // Get a local date/time.
        bLocal = TRUE;
        dtObj = CkDateTime_GetDtObj(dt,bLocal);

        printf("%d: %s, %s, %d-%d-%d:%d:%d\n",i,itemKey,itemSizeDecimalStr,CkDtObj_getDay(dtObj),CkDtObj_getMonth(dtObj),CkDtObj_getYear(dtObj)
            ,CkDtObj_getHour(dtObj),CkDtObj_getMinute(dtObj));
        CkDtObj_Dispose(dtObj);

        i = i + 1;
    }

    // Sample output from the above loop:

    // 0: images/africa/, 0, 11-6-2020:20:18
    // 1: images/africa/giraffe.jpg, 262769, 11-6-2020:20:20
    // 2: images/africa/lion.jpg, 1026769, 11-6-2020:20:20
    // 3: images/sea_creatures/starfish123.jpg, 6229, 19-1-2017:10:45
    // 4: images/sea_creatures/starfish.jpg, 6229, 19-1-2017:12:7


    CkHttp_Dispose(http);
    CkXml_Dispose(xml);
    CkDateTime_Dispose(dt);

    }

 

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