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.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoStringCompare
Handle hoCredentials
Boolean iStringMatch1
Boolean iStringMatch2
Handle hoHttp
Boolean iStringMatch3
String sXmlStr
Handle hoXml
Boolean iStringMatch4
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoStringCompare
If (Not(IsComObjectCreated(hoStringCompare))) Begin
Send CreateComObject of hoStringCompare
End
// 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.
Get Create (RefClass(cComChilkatJsonObject)) To hoCredentials
If (Not(IsComObjectCreated(hoCredentials))) Begin
Send CreateComObject of hoCredentials
End
Set ComStrict Of hoCredentials To True
Get ComLoadFile Of hoCredentials "qa_data/aws/s3-compatible.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not load private S3 credentials."
Procedure_Return
End
Get ComStringOf Of hoCredentials "access_key" To sTemp1
Get ComSetString Of hoStringCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoStringCompare "" True To iStringMatch1
Get ComJsonTypeOf Of hoCredentials "access_key" To iTemp1
If ((iTemp1 <> 1) Or (iStringMatch1 = True)) Begin
Showln "Missing or invalid access_key."
Procedure_Return
End
Get ComStringOf Of hoCredentials "secret_key" To sTemp1
Get ComSetString Of hoStringCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoStringCompare "" True To iStringMatch2
Get ComJsonTypeOf Of hoCredentials "secret_key" To iTemp1
If ((iTemp1 <> 1) Or (iStringMatch2 = True)) Begin
Showln "Missing or invalid secret_key."
Procedure_Return
End
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Get ComStringOf Of hoCredentials "access_key" To sTemp1
Set ComAwsAccessKey Of hoHttp To sTemp1
Get ComStringOf Of hoCredentials "secret_key" To sTemp1
Set ComAwsSecretKey Of hoHttp To sTemp1
Get ComHasMember Of hoCredentials "session_token" To bTemp1
If (bTemp1 = True) Begin
Get ComStringOf Of hoCredentials "session_token" To sTemp1
Get ComSetString Of hoStringCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoStringCompare "" True To iStringMatch3
Get ComJsonTypeOf Of hoCredentials "session_token" To iTemp1
If ((iTemp1 <> 1) Or (iStringMatch3 = True)) Begin
Showln "session_token must be a nonempty string when supplied."
Procedure_Return
End
Get ComStringOf Of hoCredentials "session_token" To sTemp1
Set ComAwsSessionToken Of hoHttp To sTemp1
End
// Use the provider's documented signing region and TLS endpoint.
// This reserved example endpoint must be replaced before running.
Set ComAwsRegion Of hoHttp To "us-east-1"
Set ComAwsEndpoint Of hoHttp To "objects.example.com"
Set ComRequireSslCertVerify Of hoHttp To True
Set ComFollowRedirects Of hoHttp To False
Get ComS3_ListBuckets Of hoHttp To sXmlStr
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 <> True) Begin
Get ComLastStatus Of hoHttp To iTemp1
Showln "Request failed (transport or S3 error). HTTP status: " iTemp1
// Inspect LastErrorText privately. Do not log credentials or signed URLs.
Procedure_Return
End
Get ComLastStatus Of hoHttp To iTemp1
If (iTemp1 <> 200) Begin
Get ComLastStatus Of hoHttp To iTemp1
Showln "Unexpected HTTP status: " iTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Get ComLoadXml Of hoXml sXmlStr To iSuccess
If (iSuccess <> True) Begin
Showln "Invalid XML response."
Procedure_Return
End
Get ComTag Of hoXml To sTemp1
Get ComSetString Of hoStringCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoStringCompare "ListAllMyBucketsResult" True To iStringMatch4
If (iStringMatch4 <> True) Begin
Showln "Unexpected XML response root."
Procedure_Return
End
Get ComGetXml Of hoXml To sTemp1
Showln sTemp1
Showln "Provider bucket response received; apply its documented pagination rules."
End_Procedure