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
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
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
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
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