s3.putObject({ Bucket: bucketName, Key: fileName, Body: file, ACL: 'bucket-owner-full-control' }, function(err, data) { if (err) { console.log(err); } console.log(data) });
I use this code to upload image to server amazon s3 . But I can't upload a same name file (this name exist on server s3 already ) . How can I upload same name file , and overwrite which exist on server s3 . Thanks for any help :)
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
1 Answer. To replace an old file in S3 bucket with a new file, you can just upload your new file on top of your old file. Your new file will overwrite the existing one.
If you send the file to the existing key, it will overwrite that file once the upload is complete.
You can use S3 Versioning to keep multiple versions of an object in one bucket and enable you to restore objects that are accidentally deleted or overwritten. For example, if you delete an object, instead of removing it permanently, Amazon S3 inserts a delete marker, which becomes the current object version.
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With