Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading