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 PHP ActiveX Downloads
<?php
$success = 0;
$stringCompare = new COM("Chilkat.StringBuilder");
// 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.
$credentials = new COM("Chilkat.JsonObject");
$credentials->Strict = 1;
$success = $credentials->LoadFile('qa_data/aws/s3-compatible.json');
if ($success != 1) {
print 'Could not load private S3 credentials.' . "\n";
exit;
}
$stringCompare->SetString($credentials->stringOf('access_key'));
$stringMatch1 = $stringCompare->ContentsEqual('',1);
if (($credentials->JsonTypeOf('access_key') != 1) or ($stringMatch1 == 1)) {
print 'Missing or invalid access_key.' . "\n";
exit;
}
$stringCompare->SetString($credentials->stringOf('secret_key'));
$stringMatch2 = $stringCompare->ContentsEqual('',1);
if (($credentials->JsonTypeOf('secret_key') != 1) or ($stringMatch2 == 1)) {
print 'Missing or invalid secret_key.' . "\n";
exit;
}
$http = new COM("Chilkat.Http");
$http->AwsAccessKey = $credentials->stringOf('access_key');
$http->AwsSecretKey = $credentials->stringOf('secret_key');
if ($credentials->HasMember('session_token') == 1) {
$stringCompare->SetString($credentials->stringOf('session_token'));
$stringMatch3 = $stringCompare->ContentsEqual('',1);
if (($credentials->JsonTypeOf('session_token') != 1) or ($stringMatch3 == 1)) {
print 'session_token must be a nonempty string when supplied.' . "\n";
exit;
}
$http->AwsSessionToken = $credentials->stringOf('session_token');
}
// Use the provider's documented signing region and TLS endpoint.
// This reserved example endpoint must be replaced before running.
$http->AwsRegion = 'us-east-1';
$http->AwsEndpoint = 'objects.example.com';
$http->RequireSslCertVerify = 1;
$http->FollowRedirects = 0;
$xmlStr = $http->s3_ListBuckets();
if ($http->LastMethodSuccess != 1) {
print 'Request failed (transport or S3 error). HTTP status: ' . $http->LastStatus . "\n";
// Inspect LastErrorText privately. Do not log credentials or signed URLs.
exit;
}
if ($http->LastStatus != 200) {
print 'Unexpected HTTP status: ' . $http->LastStatus . "\n";
exit;
}
$xml = new COM("Chilkat.Xml");
$success = $xml->LoadXml($xmlStr);
if ($success != 1) {
print 'Invalid XML response.' . "\n";
exit;
}
$stringCompare->SetString($xml->Tag);
$stringMatch4 = $stringCompare->ContentsEqual('ListAllMyBucketsResult',1);
if ($stringMatch4 != 1) {
print 'Unexpected XML response root.' . "\n";
exit;
}
print $xml->getXml() . "\n";
print 'Provider bucket response received; apply its documented pagination rules.' . "\n";
?>