# HG changeset patch # User Brian Neal # Date 1422412506 21600 # Node ID 9a3019f2c7dc697f6265ec72a9aa6e5a99d23b4b # Parent 13f2d4393ec4c47e4969438d27a5926f670dc250 Base64 encode filename to make it shorter. diff -r 13f2d4393ec4 -r 9a3019f2c7dc core/management/commands/ssl_images.py --- a/core/management/commands/ssl_images.py Thu Jan 15 21:05:05 2015 -0600 +++ b/core/management/commands/ssl_images.py Tue Jan 27 20:35:06 2015 -0600 @@ -6,6 +6,7 @@ - Non SG101 images that use http: are downloaded, resized, and uploaded to an S3 bucket. The src attribute is replaced with the new S3 URL. """ +import base64 import logging from optparse import make_option import os.path @@ -139,6 +140,11 @@ image.save(img_path) +def gen_key(): + """Return a random key.""" + return base64.b64encode(uuid.uuid4().bytes, '-_').rstrip('=') + + def upload_image(img_path): """Upload image file located at img_path to our S3 bucket. @@ -146,9 +152,8 @@ """ logger.info("upload_image starting") # Make a unique name for the image in the bucket - unique_key = uuid.uuid4().hex ext = os.path.splitext(img_path)[1] - file_key = unique_key + ext + file_key = gen_key() + ext try: return bucket.upload_from_filename(file_key, img_path, public=True) except IOError as ex: