Below is an example for my scenario,
- 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’
- User again uploads image with the same name ‘example.jpeg’ to the same directory.
- 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
>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.