Skip to content

Instantly share code, notes, and snippets.

@StevenFerreira
Created April 14, 2016 19:58
Show Gist options
  • Select an option

  • Save StevenFerreira/2c2b1c950b01090bbbfb3c8b3e333c61 to your computer and use it in GitHub Desktop.

Select an option

Save StevenFerreira/2c2b1c950b01090bbbfb3c8b3e333c61 to your computer and use it in GitHub Desktop.
Non overwritable private S3 storage
# Package
# pip install django-storages
from storages.backends.s3boto import S3BotoStorage
class NonOverwritablePrivateS3BotoStorage(S3BotoStorage):
"""
AWS S3 storage that will save files to the 'media' directory without
overwriting them.
See storages S3BotoStorage source code in:
storages.backends.s3boto.py @ S3BotoStorage
Override default values:
location - the upload location directory
file_overwrite - whether to overwrite existing files or not
default_acl - the access permissions to the uploaded files
See Canned ACL section in the AWS docs below
http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html
"""
location = 'media'
file_overwrite = False # override default AWS_S3_FILE_OVERWRITE=True
default_acl = 'private' # override default AWS_DEFAULT_ACL='public-read'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment