var cos = new COS({
getAuthorization: function (options, callback) {
var authorization = COS.getAuthorization({
SecretId: '*****',
SecretKey: '*****',
Method: options.Method,
Key: options.Key,
Query: {},
Headers: {
'Access-Control-Allow-Origin': '*'
//这里怎样设置,请教一下,现在不管这样设置都是
//Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access
},
Expires: 60,
});
callback(authorization);
}
});
Header 不支持设置跨域相关字段,需要到 Bucket 设置的 CORS 配置里配。
另外如果请求的时候想带 Header,应该这样写:
cos.sliceUploadFile({
Bucket: 'test',
Region: 'ap-guangzhou',
Key: '1.zip',
FilePath: './1.zip'
Headers:{
'x-cos-meta-xxx': 'xxx'
}
}, function (err, data) {
console.log(err, data);
});
var COS = require('cos-nodejs-sdk-v5');
// 创建实例
var cos = new COS({
AppId: '1250000000',
SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
});
// 分片上传
cos.sliceUploadFile({
Bucket: 'test',
Region: 'ap-guangzhou',
Key: '1.zip',
FilePath: './1.zip'
}, function (err, data) {
console.log(err, data);
});
这样写试试,这里我用的是nodejs,如果你用的是js语言,可能需要重写。
相似问题