跨域资源共享

设置跨域资源共享

putBucketCors操作将在指定的 bucket 上设定一个跨域资源共享(CORS)的规则,如果原规则存在则覆盖原规则。

var MSS = require('mos-mss');
var client = new MSS({
    accessKeyId: '<accessKeyId>',
    accessKeySecret: '<accessKeySecret>'
});

var result = client.putBucketCors('Bucket', {
    CORSConfiguration: {
        CORSRule: [
            {
                AllowedMethods: [
                    'GET',
                /* more items */
                ],
                AllowedOrigin: [
                    'http://www.example2.com',
                    'http://www.example1.com',
                /* more items */
                ],
                AllowedHeader: [
                    '*',
                /* more items */
                ],
                MaxAgeSeconds: 0
            },
        /* more items */
        ]
    }
});
result.then(function (res) {
    console.log(res);
});

查看跨域资源共享

getBucketCors操作用于获取指定的Bucket目前的CORS规则。

var MSS = require('mos-mss');
var client = new MSS({
    accessKeyId: '<accessKeyId>',
    accessKeySecret: '<accessKeySecret>'
});

var result = client.getBucketCors('Bucket');
result.then(function (res) {
    console.log(res);
});

删除跨域资源共享

deleteBucketCors操作将在指定的bucket上设定一个跨域资源共享(CORS)的规则,如果原规则存在则覆盖原规则。

var MSS = require('mos-mss');
var client = new MSS({
    accessKeyId: '<accessKeyId>',
    accessKeySecret: '<accessKeySecret>'
});

var result = client.deleteBucketCors('Bucket');
result.then(function (res) {
    console.log(res);
});