Created
February 2, 2016 23:52
-
-
Save harshavardhana/459ca3f18bbc88521c5c to your computer and use it in GitHub Desktop.
AWS SDK PHP example with minio server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Include the SDK using the Composer autoloader | |
date_default_timezone_set('America/Los_Angeles'); | |
require 'vendor/autoload.php'; | |
$s3 = new Aws\S3\S3Client([ | |
'version' => 'latest', | |
'region' => 'us-east-1', | |
'endpoint' => 'http://localhost:9000' | |
]); | |
$result = $s3->listBuckets(); | |
echo "ListBuckets: \n"; | |
foreach ($result['Buckets'] as $bucket) { | |
echo $bucket['Name'] . " " . $bucket['CreationDate'] . "\n"; | |
} | |
echo "ListObjects: \n"; | |
$results = $s3->getPaginator('ListObjects', [ | |
'Bucket' => 'testbucket' | |
]); | |
foreach ($results as $result) { | |
foreach ($result['Contents'] as $object) { | |
echo $object['Key'] . " " . $object['Size'] . "\n"; | |
} | |
} | |
echo "ListObjects: delimited\n"; | |
$results = $s3->getPaginator('ListObjects', [ | |
'Bucket' => 'testbucket', | |
'Delimiter' => '/' | |
]); | |
$expression = '[CommonPrefixes[].Prefix, Contents[].Key][]'; | |
foreach ($results->search($expression) as $item) { | |
echo $item . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment