Mercurial > public > sg101
diff core/image_uploader.py @ 886:3d635fd53ef0
Merge with upstream.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 03 Feb 2015 19:52:09 -0600 |
parents | ee47122d6277 |
children | 51a2051588f5 |
line wrap: on
line diff
--- a/core/image_uploader.py Tue Feb 03 19:51:12 2015 -0600 +++ b/core/image_uploader.py Tue Feb 03 19:52:09 2015 -0600 @@ -3,6 +3,7 @@ The image can be resized and a thumbnail can be generated and uploaded as well. """ +from base64 import b64encode import logging from io import BytesIO import os.path @@ -18,6 +19,11 @@ logger = logging.getLogger(__name__) +def make_key(): + """Generate a random key suitable for a filename""" + return b64encode(uuid.uuid4().bytes, '-_').rstrip('=') + + def upload(fp, bucket, metadata=None, new_size=None, thumb_size=None): """Upload an image file to a given S3Bucket. @@ -54,7 +60,7 @@ # to perform on it fail if this is the case. To get around these issues, # we make a copy of the file on the file system and operate on the copy. # First generate a unique name and temporary file path. - unique_key = uuid.uuid4().hex + unique_key = make_key() ext = os.path.splitext(fp.name)[1] temp_name = os.path.join(tempfile.gettempdir(), unique_key + ext)