# Path: buckets/utils.py
# def validate_settings():
#     assert settings.AWS, \
#         "No AWS settings found"
#     assert settings.AWS.get('ACCESS_KEY'), \
#         "AWS access key is not set in settings"
#     assert settings.AWS.get('SECRET_KEY'), \
#         "AWS secret key is not set in settings"
#     assert settings.AWS.get('BUCKET'), \
#         "AWS bucket name is not set in settings"
# 
# def random_id():
#     rand_id = [random.randint(0, 0xFF) for i in range(ID_FIELD_LENGTH)]
#     return (byte_to_letter(rand_id[0]) +
#             ''.join(map(byte_to_base32_chr, rand_id[1:])))
# 
# def ensure_dirs(*args):
#     for dir in args:
#         path = os.path.join(settings.MEDIA_ROOT, 's3', dir)
#         if not os.path.exists(path):
#             os.makedirs(path)


import os
import boto3
from django.conf import settings
from django.core.files.storage import Storage
from django.core.files import File
from botocore.client import Config
from botocore.exceptions import ClientError
from .utils import validate_settings, random_id, ensure_dirs
            else:
                raise e
        else:
            return True

    def get_signed_url(self, key):
        dir = ''
        if '/' in key:
            dir = key[:key.rfind('/') + 1]

        ext = key[key.rfind('.'):]
        s3_key = ''

        while not s3_key:
            temp_key = dir + random_id() + ext

            if not self.exists(temp_key):
                s3_key = temp_key

        condtions = []
        if self.max_size:
            condtions.append(["content-length-range", 0, self.max_size])

        params = {
            'Bucket': self.bucket_name,
            'Key': s3_key,
            'Conditions': condtions
        }
        client = boto3.client(
            's3',

# Path: buckets/utils.py
# def validate_settings():
#     assert settings.AWS, \
#         "No AWS settings found"
#     assert settings.AWS.get('ACCESS_KEY'), \
#         "AWS access key is not set in settings"
#     assert settings.AWS.get('SECRET_KEY'), \
#         "AWS secret key is not set in settings"
#     assert settings.AWS.get('BUCKET'), \
#         "AWS bucket name is not set in settings"
# 
# def random_id():
#     rand_id = [random.randint(0, 0xFF) for i in range(ID_FIELD_LENGTH)]
#     return (byte_to_letter(rand_id[0]) +
#             ''.join(map(byte_to_base32_chr, rand_id[1:])))
# 
# def ensure_dirs(*args):
#     for dir in args:
#         path = os.path.join(settings.MEDIA_ROOT, 's3', dir)
#         if not os.path.exists(path):
#             os.makedirs(path)


# Path: buckets/storage.py
import os
import boto3
from django.conf import settings
from django.core.files.storage import Storage
from django.core.files import File
from botocore.client import Config
from botocore.exceptions import ClientError
from .utils import validate_settings, random_id, ensure_dirs

            else:
                raise e
        else:
            return True

    def get_signed_url(self, key):
        dir = ''
        if '/' in key:
            dir = key[:key.rfind('/') + 1]

        ext = key[key.rfind('.'):]
        s3_key = ''

        while not s3_key:
            temp_key = dir + random_id() + ext

            if not self.exists(temp_key):
                s3_key = temp_key

        condtions = []
        if self.max_size:
            condtions.append(["content-length-range", 0, self.max_size])

        params = {
            'Bucket': self.bucket_name,
            'Key': s3_key,
            'Conditions': condtions
        }
        client = boto3.client(
            's3',

            aws_access_key_id=self.access_key,