问题:web端js用sts方式上传文件时报403错误
web端js代码:
/*附件上传*/
var checkpoint_temp;
function multipartUploadWithSts(storeAs, file, cpt) {
OSS.urllib.request("http://member.xymdev.com:2700/ways/merchant/ui/order/get/oss/sts/evidence", {method: 'POST'}, function (err, response) {
var result, errmsg;
if (err) {
return alert(err);
}
try {
result = JSON.parse(response);
} catch (e) {
errmsg = 'parse sts response info error: ' + e.message;
return alert(errmsg);
}
console.log(result)
var client = new OSS.Wrapper({
accessKeyId: result.data.accessKeyId,
accessKeySecret: result.data.accessKeySecret,
stsToken: result.data.securityToken,
bucket: 'pri-bucket',
endpoint: 'http://oss-cn-shanghai.aliyuncs.com'
});
multitest(client, storeAs, file, cpt);
})
};
var upload = function () {
var client = null;
var file = document.getElementById('uploadFile').files[0];
console.log(file);
var storeAs = file['name'];
console.log("upload file=",file)
multipartUploadWithSts(storeAs, file)
};
function multitest (ossClient, storeAs, file, cpt) {
//console.log(file.name + ' => ' + storeAs);
var checkpoint_temp;
if (cpt) {
console.log("multitest with cpt")
ossClient.multipartUpload(storeAs, file,{
parallel: 2,
checkpoint: cpt,
progress: function* (percent, cpt) {
console.log('Progress: ' + percent);
checkpoint_temp = cpt
}
}).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
multipartUploadWithSts(storeAs, file, checkpoint_temp)
});
} else {
console.log("multitest without cpt")
ossClient.multipartUpload(storeAs, file,{
parallel: 2,
progress: function* (percent, cpt) {
console.log('Progress: ' + percent);
checkpoint_temp = cpt
}
}).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
multipartUploadWithSts(storeAs, file, checkpoint_temp)
});
}
};
document.getElementById('uploadFile').onchange = upload;
错误信息:
Failed to load http://xym-ways-dev-private.oss-cn-hangzhou.aliyuncs.com/Jung-Ki-Song.jpg: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://member.xymdev.com:2700' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
后端返回sts凭证: