If I upload a file to S3 with the filename identical to a filename (Key) of an object in the bucket it overwrites it.
What are the options to avoid overwriting files with identical filenames?
I enabled versioning in my bucket thinking it will solve the problem but objects are still overwritten.
Edit: as of Aug 20, 2024 S3 supports conditional writes, see https://aws.amazon.com/about-aws/whats-new/2024/08/amazon-s3-conditional-writes/ and https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-writes.html
You can use If-Match
and If-None-Match
to specify if you expect a specific etag (e.g. for optimistic locking) or if you expect no file to exist at all.
Original answer:
My comment from above doesn't work. I thought the WRITE
ACL would apply to objects as well, but it only works on buckets.
Since you enabled versioning, your objects aren't overwritten. But if you don't specify the version in your GET request or URL, the latest version will be taken. This means when you put and object into S3 you need to save the versionID the response tells you in order to retrieve the very first object.
See Amazon S3 ACL for read-only and write-once access for more.