我想检查特定存储桶是否存在,如果不存在则创建新存储桶。
我需要知道如何使用aws.phar + php
检测存储桶是否已存在这是伪代码
$bucket = 'my-bucket';
//some code to detect if bucket name 'my-bucket' exists *suggest here*
//$myBucketExists = $client->someMethode()
if(!$myBucketExists){
$result = $client->createBucket(array(
'Bucket' => $bucket
));
// Wait until the bucket is created
$client->waitUntil('BucketExists', array('Bucket' => $bucket));
}
// rest of the code using the bucket
答案 0 :(得分:4)
$myBucketExists = $client->headBucket( array('Bucket' => $bucket) );
答案 1 :(得分:1)
试试这个:
$s3 = $this->awsService->get('S3');
if(!$s3->doesBucketExist($bucket)) {
$s3->createBucket(array(
'Bucket' => $bucket
));
}