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不能起作用。有想法吗?
答案 0 :(得分:0)
您错误地指定了Key
。不要在密钥中指定存储桶名称。这就是Bucket
的目的。
var paramsCopy = {
Bucket: destBucket,
CopySource: srcBucket + '/' + sourceObject,
Key: 'testy.mp4'
};