跨域资源共享

跨域资源共享(CORS)允许web端的应用程序访问不属于本域的资源。MSS提供接口方便开发者控制跨域访问的权限。

设置跨域资源共享

require '/path/to/mss.phar';

$accessKeyId = "<从MSS获得的AccessKeyId>";
$accessKyeSecret = "<从MSS获得的AccessKeySecret>";
$endpoint = "<选定的MSS数据中心访问域名,例如http://mtmss.com>";
$bucket = "<使用的bucketName,注意命名规范>";

$mssClient = Mss\S3\S3Client::factory([
        'endpoint' => $endpoint,
        'key'    => $accessKeyId,
        'secret' => $accessKeySecret,]);

$command = $mssClient->getCommand('PutBucketCors', array(
        'Bucket' => $bucket,
        'CORSRules' => array(
            array(
               'AllowedMethods' => array('GET'),
               'AllowedOrigins' => array('http://abc.com')
            )
         )));

$result = $command->execute();
echo $result;

查看跨域资源共享

require '/path/to/mss.phar';

$accessKeyId = "<从MSS获得的AccessKeyId>";
$accessKyeSecret = "<从MSS获得的AccessKeySecret>";
$endpoint = "<选定的MSS数据中心访问域名,例如http://mtmss.com>";
$bucket = "<使用的bucketName,注意命名规范>";

$mssClient = Mss\S3\S3Client::factory([
        'endpoint' => $endpoint,
        'key'    => $accessKeyId,
        'secret' => $accessKeySecret,]);

$result = $mssClient->getBucketCors(array('Bucket'=>$bucket));
echo $result;

删除跨域资源共享

require '/path/to/mss.phar';

$accessKeyId = "<从MSS获得的AccessKeyId>";
$accessKyeSecret = "<从MSS获得的AccessKeySecret>";
$endpoint = "<选定的MSS数据中心访问域名,例如http://mtmss.com>";
$bucket = "<使用的bucketName,注意命名规范>";

$mssClient = Mss\S3\S3Client::factory([
        'endpoint' => $endpoint,
        'key'    => $accessKeyId,
        'secret' => $accessKeySecret,]);

$result = $mssClient->deleteBucketCors(array('Bucket'=>$bucket));
echo $result;