[Fixed]-Django-storages with Amazon S3 – prevent overwriting

30👍

If you are using the s3boto backend not the old s3 backend in django-storages then you can change this using the AWS_S3_FILE_OVERWRITE setting: https://bitbucket.org/david/django-storages/src/83fa2f0ba20c/storages/backends/s3boto.py#cl-43

1👍

@Mark Lavin’s answer aptly points out that setting AWS_S3_FILE_OVERWRITE to False avoids this problem.

You may additionally want to improve your file name-spacing a little bit. You can save files under whatever name on S3 you want (it doesn’t have to be the name of the file the user uploaded). So you could save your file with the name “user_uploads/[user_id]/[user_generated_file_name]”. You can also set the file name to be whatever you want as part of a download. If you save the user’s uploaded file name as a field on your model, you can then specify that as the file name in the view that downloads a file.

👤Zags

Leave a comment