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 my Amazon S3 cloud storage. But I can't upload a file with the same name (this name exist on the server S3 already).
How can I upload a file with the same name and overwrite the already existing one in S3?
Thanks for any help :)
22 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.
2I guess you've encountered the default caching mechanism which is 24 hours, this results in not receiving the latest stored object. To override this, add parameter to putObject():
CacheControl: "no-cache" or Expires: new Date()