Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to upload same name file to amazon s3 and overwrite exist file

Tags:

    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 :)

like image 639
Trần Dương Avatar asked Nov 08 '16 07:11

Trần Dương


People also ask

Does S3 overwrite file with same name?

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.

Can you overwrite a file in S3?

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.

Does S3 copy overwrite?

If you send the file to the existing key, it will overwrite that file once the upload is complete.

Can a S3 bucket store multiple versions of the same file?

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.


1 Answers

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.

like image 147
manojkumarm Avatar answered Oct 24 '22 05:10

manojkumarm