putObject可以正常工作:
var destBucket = 'DESTBUCKETNAME';
var params = {
Body: '01110100 01100101 01110011 01110100 01100110 01101001 01101100 01100101 01101000 01100101 01110010 01100101 ',
Bucket: destBucket,
Key: "tester.mp4"
};
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
这将上传文件并返回成功的响应。
但是,copyObject返回目标对象位置禁止的403:
var sourceObject = 'testsrcfile.mp4';
var srcBucket = 'BUCKETNAME';
var destBucket = 'DESTBUCKETNAME';
var paramsCopy = {
Bucket: destBucket,
CopySource: srcBucket + '/' + sourceObject,
Key: destBucket + '/' + 'testy.mp4'
};
s3.copyObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
错误:
PUT https://DESTBUCKETNAME.s3.us-west-1.amazonaws.com/DESTBUCKETNAME/testy.mp4 403 (Forbidden)
这是目标存储桶的CORS配置:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<ExposeHeader>ETag</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我不明白为什么putObject起作用而copyObject不能起作用。有什么想法吗?
最佳答案
您错误地指定了Key
。不要在密钥中指定存储桶名称。这就是Bucket
的目的。
var paramsCopy = {
Bucket: destBucket,
CopySource: srcBucket + '/' + sourceObject,
Key: 'testy.mp4'
};
关于javascript - S3 JS SDK复制对象403禁止,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52107309/