如何使用node.js将对象从s3复制到s3 [英] How to copy the object from s3 to s3 using node.js
问题描述
我想知道如何使用node.js将对象从s3复制到s3使用aws s3命令,可以按以下步骤执行.
I would like to know how to copy the object from s3 to s3 using node.js With the aws s3 command, It could be executed as follows.
s3 cp --recursive s3://xx/yy s3://zz/aa
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property
我指的是上面的链接,但是我不知道如何使用node.js
I refer to above link,But I don't know how to do it using node.js
有什么主意吗?
推荐答案
If you just want to copy one object copyObject API.
var params = {
Bucket: "destinationbucket",
CopySource: "/sourcebucket/sourceKeyName",
Key: "targetKeyName"
};
s3.copyObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
如果要对存储桶中的所有对象进行递归执行,则
If you want to perform recursively for all objects in a bucket, then
-
使用 listObjectsV2 API.
如果在 source-bucket 中启用了版本控制,并且您要复制密钥的特定版本,请调用
If versioning is enabled in the source-bucket and you want to copy a specific version of the key, Invoke the listObjectVersions API as well and get the Version-Id
for each S3 Key.
注意:如果未启用版本控制,则可以忽略STEP-2.
分别为在步骤1和步骤2中获得的每个S3密钥和 Version-Id
调用 copyObject
. Version-id
是可选的.
Call copyObject
for each S3 Key and the Version-Id
obtained in Step-1 and Step-2 respectively. Version-id
is optional.
这篇关于如何使用node.js将对象从s3复制到s3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!