Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.6.0+

S3: Connect to an S3-Compatible Provider

See more S3 - HTTP Examples

Uses Chilkat.Http with Amazon S3 general purpose buckets and Signature Version 4. These examples do not cover directory buckets/S3 Express, access-point ARNs, Outposts, or other specialized endpoints. They target the commercial AWS partition; other partitions need their documented endpoint suffix.

Load private qa_data/aws/s3-compatible.json containing nonempty string fields access_key and secret_key, plus session_token for temporary credentials. Prefer short-lived role credentials. These samples do not discover AWS profiles or refresh credentials. Set the bucket's actual region and replace sample bucket names and object keys. TLS certificate verification is explicitly enabled. Keep detailed HTTP diagnostics private because they can contain credentials or presigned URLs.

Uses separate provider credentials in qa_data/aws/s3-compatible.json; do not send AWS credentials to an unrelated endpoint. Replace the reserved example hostname and signing region with the provider's documented values. The endpoint is a hostname without an https:// prefix. SigV4 remains the default and TLS verification stays enabled.

S3 compatibility is not identical to AWS S3. Verify authentication, addressing style, supported headers, pagination, versioning, checksums, and error semantics with the provider. This example calls the unpaginated bucket helper and displays the validated XML response; it does not claim that every provider has the same quota or pagination behavior as AWS.

AWS reference

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_StringCompare
oleobject loo_Credentials
long li_StringMatch1
long li_StringMatch2
oleobject loo_Http
long li_StringMatch3
string ls_XmlStr
oleobject loo_Xml
long li_StringMatch4

li_Success = 0

loo_StringCompare = create oleobject
li_rc = loo_StringCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_StringCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.
//  Load private credentials; never put access keys or session tokens in source.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")

loo_Credentials.Strict = 1
li_Success = loo_Credentials.LoadFile("qa_data/aws/s3-compatible.json")
if li_Success <> 1 then
    Write-Debug "Could not load private S3 credentials."
    destroy loo_StringCompare
    destroy loo_Credentials
    return
end if

loo_StringCompare.SetString(loo_Credentials.StringOf("access_key"))
li_StringMatch1 = loo_StringCompare.ContentsEqual("",1)
if (loo_Credentials.JsonTypeOf("access_key") <> 1) OR (li_StringMatch1 = 1) then
    Write-Debug "Missing or invalid access_key."
    destroy loo_StringCompare
    destroy loo_Credentials
    return
end if

loo_StringCompare.SetString(loo_Credentials.StringOf("secret_key"))
li_StringMatch2 = loo_StringCompare.ContentsEqual("",1)
if (loo_Credentials.JsonTypeOf("secret_key") <> 1) OR (li_StringMatch2 = 1) then
    Write-Debug "Missing or invalid secret_key."
    destroy loo_StringCompare
    destroy loo_Credentials
    return
end if

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

loo_Http.AwsAccessKey = loo_Credentials.StringOf("access_key")
loo_Http.AwsSecretKey = loo_Credentials.StringOf("secret_key")
if loo_Credentials.HasMember("session_token") = 1 then
    loo_StringCompare.SetString(loo_Credentials.StringOf("session_token"))
    li_StringMatch3 = loo_StringCompare.ContentsEqual("",1)
    if (loo_Credentials.JsonTypeOf("session_token") <> 1) OR (li_StringMatch3 = 1) then
        Write-Debug "session_token must be a nonempty string when supplied."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Http
        return
    end if

    loo_Http.AwsSessionToken = loo_Credentials.StringOf("session_token")
end if

//  Use the provider's documented signing region and TLS endpoint.
//  This reserved example endpoint must be replaced before running.
loo_Http.AwsRegion = "us-east-1"
loo_Http.AwsEndpoint = "objects.example.com"
loo_Http.RequireSslCertVerify = 1
loo_Http.FollowRedirects = 0
ls_XmlStr = loo_Http.S3_ListBuckets()
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug "Request failed (transport or S3 error). HTTP status: " + string(loo_Http.LastStatus)
    //  Inspect LastErrorText privately. Do not log credentials or signed URLs.
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Http
    return
end if

if loo_Http.LastStatus <> 200 then
    Write-Debug "Unexpected HTTP status: " + string(loo_Http.LastStatus)
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Http
    return
end if

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

li_Success = loo_Xml.LoadXml(ls_XmlStr)
if li_Success <> 1 then
    Write-Debug "Invalid XML response."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Http
    destroy loo_Xml
    return
end if

loo_StringCompare.SetString(loo_Xml.Tag)
li_StringMatch4 = loo_StringCompare.ContentsEqual("ListAllMyBucketsResult",1)
if li_StringMatch4 <> 1 then
    Write-Debug "Unexpected XML response root."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Http
    destroy loo_Xml
    return
end if

Write-Debug loo_Xml.GetXml()
Write-Debug "Provider bucket response received; apply its documented pagination rules."


destroy loo_StringCompare
destroy loo_Credentials
destroy loo_Http
destroy loo_Xml