Quantcast
Channel: How can I move (not copy) a file in AWS S3 using their sdk? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

How can I move (not copy) a file in AWS S3 using their sdk?

$
0
0

I need to move a file in AWS s3 bucket to another location, example:

I've looked over the documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html, but haven't found any mention of either moving nor updating the file (I'm thinking I could update the file Key path...).

So far, it seems I need to copy the file then remove the old one? Is there a more straightforward way of doing it?

My current code which copies then removes old file:

function moveFileInAws(fromLocation, toLocation, callback) {  awsSdk.copyObject({    Bucket: BUCKET_NAME,    ACL: 'public-read',    CopySource: fromLocation,    Key: toLocation  }, (err, data) => {    if (err) {        console.log(err)        return callback("Couldn't copy files in directory")    }    // callback()    awsSdk.deleteObject({ Key: fromLocation }, (err, data) => {      if (err) {        console.log("Couldn't delete files in directory")        console.log(err)        return callback("Couldn't delete files in directory")      }      callback()    })  })}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>