How to copy the object from s3 to s3 using node.js

后端 未结 4 901
小蘑菇
小蘑菇 2021-02-19 13:04

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  s         


        
4条回答
  •  情话喂你
    2021-02-19 13:24

    If you want to really move (so not just copy, but in addition remove the source file)

    const moveAndDeleteFile = async (file,inputfolder,targetfolder) => {
        const s3 = new AWS.S3();
    
        const copyparams = {
            Bucket : bucketname,
            CopySource : bucketname + "/" + inputfolder + "/" + file, 
            Key : targetfolder + "/" + file
        };
    
        await s3.copyObject(copyparams).promise();
    
        const deleteparams = {
            Bucket : bucketname,
            Key : inputfolder + "/" + file
        };
    
        await s3.deleteObject(deleteparams).promise();
        ....
    }
    

提交回复
热议问题