コード例 #1
0
def load(context, url, callback):
    enable_http_loader = context.config.get('AWS_ENABLE_HTTP_LOADER',
                                            default=False)

    if enable_http_loader and url.startswith('http'):
        return http_loader.load_sync(context,
                                     url,
                                     callback,
                                     normalize_url_func=_normalize_url)

    url = urllib2.unquote(url)

    bucket = context.config.get('S3_LOADER_BUCKET', default=None)

    if not bucket:
        bucket, url = _get_bucket(url,
                                  root_path=context.config.S3_LOADER_ROOT_PATH)

    if _validate_bucket(context, bucket):
        bucket_loader = Bucket(connection=get_connection(context), name=bucket)
        file_key = None
        try:
            file_key = bucket_loader.get_key(url)
        except Exception, e:
            logger.warn("ERROR retrieving image from S3 {0}: {1}".format(
                url, str(e)))

        if file_key:
            callback(file_key.read())
            return
コード例 #2
0
ファイル: s3_loader.py プロジェクト: guilhermef/aws
def load(context, url, callback):
    enable_http_loader = context.config.get('AWS_ENABLE_HTTP_LOADER', default=False)

    if enable_http_loader and url.startswith('http'):
        return http_loader.load_sync(context, url, callback, normalize_url_func=_normalize_url)

    url = urllib2.unquote(url)

    bucket = context.config.get('S3_LOADER_BUCKET', default=None)

    if not bucket:
        bucket, url = _get_bucket(url, root_path=context.config.S3_LOADER_ROOT_PATH)

    if _validate_bucket(context, bucket):
        bucket_loader = Bucket(
            connection=get_connection(context),
            name=bucket
        )
        file_key = None
        try:
            file_key = bucket_loader.get_key(url)
        except Exception, e:
            logger.warn("ERROR retrieving image from S3 {0}: {1}".format(url, str(e)))

        if file_key:
            callback(file_key.read())
            return
コード例 #3
0
def _generate_presigned_url(context, bucket, key):
    connection = get_connection(context)
    expiry = 60 * 60
    presigned_url = connection.generate_url(
        expiry,
        'GET',
        bucket,
        key,
    )
    return presigned_url
コード例 #4
0
ファイル: presigning_loader.py プロジェクト: pgr0ss/aws
def _generate_presigned_url(context, bucket, key):
    connection = get_connection(context)
    expiry = 60 * 60
    presigned_url = connection.generate_url(
        expiry,
        'GET',
        bucket,
        key,
    )
    return presigned_url
コード例 #5
0
ファイル: s3_loader.py プロジェクト: pgr0ss/aws
def load_sync(context, url, callback):
    if _use_http_loader(context, url):
        return http_loader.load_sync(context, url, callback, normalize_url_func=_normalize_url)

    bucket, key = _get_bucket_and_key(context, url)

    if _validate_bucket(context, bucket):
        bucket_loader = Bucket(
            connection=get_connection(context),
            name=bucket
        )
        file_key = None
        try:
            file_key = bucket_loader.get_key(url)
        except Exception, e:
            logger.warn("ERROR retrieving image from S3 {0}: {1}".format(url, str(e)))

        if file_key:
            callback(file_key.read())
            return
コード例 #6
0
ファイル: s3_loader.py プロジェクト: Vmadmax/aws
def load_sync(context, url, callback):
    if _use_http_loader(context, url):
        return http_loader.load_sync(context,
                                     url,
                                     callback,
                                     normalize_url_func=_normalize_url)

    bucket, key = _get_bucket_and_key(context, url)

    if _validate_bucket(context, bucket):
        bucket_loader = Bucket(connection=get_connection(context), name=bucket)
        file_key = None

        try:
            file_key = bucket_loader.get_key(key)
        except Exception, e:
            logger.warn("ERROR retrieving image from S3 {0}: {1}".format(
                key, str(e)))

        if file_key:
            callback(file_key.read())
            return