putBucketCors() 공개 메소드

在指定的bucket上设定一个跨域资源共享(CORS)的规则,如果原规则存在则覆盖原规则
public putBucketCors ( string $bucket, OSS\Model\CorsConfig $corsConfig, array $options = NULL ) : null
$bucket string bucket名称
$corsConfig OSS\Model\CorsConfig 跨域资源共享配置,具体规则参见SDK文档
$options array array
리턴 null
예제 #1
0
/**
 * 设置bucket的cors配置
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 存储空间名称
 * @return null
 */
function putBucketCors($ossClient, $bucket)
{
    $corsConfig = new CorsConfig();
    $rule = new CorsRule();
    $rule->addAllowedHeader("x-oss-header");
    $rule->addAllowedOrigin("http://www.b.com");
    $rule->addAllowedMethod("POST");
    $rule->setMaxAgeSeconds(10);
    $corsConfig->addRule($rule);
    try {
        $ossClient->putBucketCors($bucket, $corsConfig);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print __FUNCTION__ . ": OK" . "\n";
}