bradleyg / django-s3direct

Directly upload files to S3 compatible services with Django.
MIT License
661 stars 234 forks source link

Where to find docs for S3DIRECT_DESTINATIONS = {}? #162

Closed ghost closed 5 years ago

ghost commented 6 years ago

Hey there. Thank you for making this! Just got it working tonight.

Where might I be able to find more documentation the options available for S3DIRECT_DESTINATIONS = {}? They are quite useful.

I've looked around boto and django-storages to no avail. In forks I've seen options like allowed_extensions. Just want to make sure I'm not missing anything already written.

roxel commented 6 years ago

Library documentation for information you're asking about can be found here: https://github.com/bradleyg/django-s3direct#settingspy. Looking at the source code, I think only option missing is 'region' that can override global S3DIRECT_REGION setting. For the options available for S3 specific values, e.g. acl, I think the best resource would be AWS S3 REST API docs: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html

# Destinations, with the following keys:
#
# key [required] Where to upload the file to, can be either:
#     1. '/' = Upload to root with the original filename.
#     2. 'some/path' = Upload to some/path with the original filename.
#     3. functionName = Pass a function and create your own path/filename.
# key_args [optional] Arguments to be passed to 'key' if it's a function.
# auth [optional] An ACL function to whether the current Django user can perform this action.
# allowed [optional] List of allowed MIME types.
# acl [optional] Give the object another ACL rather than 'public-read'.
# cache_control [optional] Cache control headers, eg 'max-age=2592000'.
# content_disposition [optional] Useful for sending files as attachments.
# bucket [optional] Specify a different bucket for this particular object.
# server_side_encryption [optional] Encryption headers for buckets that require it.

S3DIRECT_DESTINATIONS = {
    'example_destination': {
        # REQUIRED
        'key': 'uploads/images',

        # OPTIONAL
        'auth': lambda u: u.is_staff, # Default allow anybody to upload
        'allowed': ['image/jpeg', 'image/png', 'video/mp4'],  # Default allow all mime types
        'bucket': 'pdf-bucket', # Default is 'AWS_STORAGE_BUCKET_NAME'
        'acl': 'private', # Defaults to 'public-read'
        'cache_control': 'max-age=2592000', # Default no cache-control
        'content_disposition': 'attachment',  # Default no content disposition
        'content_length_range': (5000, 20000000), # Default allow any size
        'server_side_encryption': 'AES256', # Default no encryption
    },
    'example_other': {
        'key': lambda filename, args: args + '/' + filename,
        'key_args': 'uploads/images',  # Only if 'key' is a function
    }
}

I hope this answers your question :)