Skip to content

Instantly share code, notes, and snippets.

@brunomichetti
Created July 11, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomichetti/72f8992ec2013e221b18641eefb566f6 to your computer and use it in GitHub Desktop.
Save brunomichetti/72f8992ec2013e221b18641eefb566f6 to your computer and use it in GitHub Desktop.
# your settings file
import os
from django.utils import timezone
from django.utils.text import slugify
EXAMPLE_DEST_KEY = 'images/example-images/'
TIMESTAMP_FORMAT = '%m-%d-%Y_%H-%M-%S-%f'
def normalize_filename(filename):
name, extension = os.path.splitext(filename)
time_stamp = timezone.now().strftime(TIMESTAMP_FORMAT)
return f'{time_stamp}--{slugify(name)}{extension}'
S3DIRECT_DESTINATIONS = {
'example_destination': {
'key': lambda filename: f'{EXAMPLE_DEST_KEY}/{normalize_filename(filename)}',
'region': AWS_S3_REGION_NAME,
'acl': 'private',
'allow_existence_optimization': False,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment