Home > Back-end >  AWS S3 file with same name does not get overwrite but gets characters added at the end of filename
AWS S3 file with same name does not get overwrite but gets characters added at the end of filename

Time:02-04

Below is an example for my scenario,

  1. I have a Django API which allows user to upload images to a certain directory, the images will be stored in an S3 bucket. Let's say the file name is 'example.jpeg'
  2. User again uploads image with the same name 'example.jpeg' to the same directory.
  3. Both of them correctly show up in the same directory but the second one gets additional characters at the end of the filename like this 'example_785PmrM.jpeg'. I suspect the additional characters are added by s3 but my research says s3 will overwrite the file with same name.

How can I enable the overwrite feature, I haven't seen any option for this.

Thanks

CodePudding user response:

S3 itself does not change a key on it's own. The only option I see that can be impacting this is Django's storage backend for S3:

AWS_S3_FILE_OVERWRITE (optional: default is True)

By default files with the same name will overwrite each other. Set this to False to have extra characters appended.

So you should set AWS_S3_FILE_OVERWRITE to True to prevent this behavior.

Depending on your exact needs, consider enabling S3 versioning so you can access previous versions of a objects as they're overwritten in S3 in the future.

  •  Tags:  
  • Related