Esempio n. 1
0
Common::println("bucket {$bucket} exist? " . ($doesExist ? "yes" : "no"));
// 获取Bucket列表
$bucketListInfo = $ossClient->listBuckets();
// 设置bucket的ACL
$ossClient->putBucketAcl($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
Common::println("bucket {$bucket} acl put");
// 获取bucket的ACL
$acl = $ossClient->getBucketAcl($bucket);
Common::println("bucket {$bucket} acl get: " . $acl);
//******************************* 完整用法参考下面函数 ****************************************************
createBucket($ossClient, $bucket);
doesBucketExist($ossClient, $bucket);
deleteBucket($ossClient, $bucket);
putBucketAcl($ossClient, $bucket);
getBucketAcl($ossClient, $bucket);
listBuckets($ossClient);
/**
 * 创建一个存储空间
 * acl 指的是bucket的访问控制权限,有三种,私有读写,公共读私有写,公共读写。
 * 私有读写就是只有bucket的拥有者或授权用户才有权限操作
 * 三种权限分别对应 (OssClient::OSS_ACL_TYPE_PRIVATE,OssClient::OSS_ACL_TYPE_PUBLIC_READ, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE)
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 要创建的存储空间名称
 * @return null
 */
function createBucket($ossClient, $bucket)
{
    try {
        $ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
    } catch (OssException $e) {
Esempio n. 2
0
{
    $buckets = $client->listBuckets();
    foreach ($buckets as $bucket) {
        echo 'Bucket: ' . $bucket->getName() . "\n";
    }
}
// Sample of create Bucket
function createBucket(OSSClient $client, $bucket)
{
    $client->createBucket(array('Bucket' => $bucket));
}
// Sample of get Bucket Acl
function getBucketAcl(OSSClient $client, $bucket)
{
    $acl = $client->getBucketAcl(array('Bucket' => $bucket));
    $grants = $acl->getGrants();
    echo $grants[0];
}
// Sample of delete Bucket
function deleteBucket(OSSClient $client, $bucket)
{
    $client->deleteBucket(array('Bucket' => $bucket));
}
$keyId = 'your-access-key-id';
$keySecret = 'your-access-key-secret';
$client = createClient($keyId, $keySecret);
$bucket = 'your-bucket-name';
listBuckets($client);
createBucket($client, $bucket);
getBucketAcl($client, $bucket);
deleteBucket($client, $bucket);