ltdconveyor/s3/upload.py
def upload_file(local_path, bucket_path, bucket,
                metadata=None, acl=None, cache_control=None):
    """Upload a file to the S3 bucket.

    This function uses the mimetypes module to guess and then set the
    Content-Type and Encoding-Type headers.

    Parameters
    ----------
    local_path : `str`
        Full path to a file on the local file system.
    bucket_path : `str`
        Destination path (also known as the key name) of the file in the
        S3 bucket.
    bucket : boto3 Bucket instance
        S3 bucket.
    metadata : `dict`, optional
        Header metadata values. These keys will appear in headers as
        ``x-amz-meta-*``.
    acl : `str`, optional
        A pre-canned access control list. See
        https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
        Default is `None`, mean that no ACL is applied to the object.
    cache_control : `str`, optional
        The cache-control header value. For example, ``'max-age=31536000'``.
    """
    logger = logging.getLogger(__name__)

    extra_args = {}
    if acl is not None:
        extra_args['ACL'] = acl
    if metadata is not None and len(metadata) > 0:  # avoid empty Metadata
        extra_args['Metadata'] = metadata
    if cache_control is not None:
        extra_args['CacheControl'] = cache_control

    # guess_type returns None if it cannot detect a type
    content_type, content_encoding = mimetypes.guess_type(local_path,
                                                          strict=False)
    if content_type is not None:
        extra_args['ContentType'] = content_type

    logger.debug(str(extra_args))

    obj = bucket.Object(bucket_path)
    # no return status from the upload_file api
    obj.upload_file(local_path, ExtraArgs=extra_args)
def upload_file(local_path, bucket_path, bucket,
                metadata=None, acl=None, cache_control=None):
    """Upload a file to the S3 bucket.

    This function uses the mimetypes module to guess and then set the
    Content-Type and Encoding-Type headers.

    Parameters
    ----------
    local_path : `str`
        Full path to a file on the local file system.
    bucket_path : `str`
        Destination path (also known as the key name) of the file in the
        S3 bucket.
    bucket : boto3 Bucket instance
        S3 bucket.
    metadata : `dict`, optional
        Header metadata values. These keys will appear in headers as
        ``x-amz-meta-*``.
    acl : `str`, optional
        A pre-canned access control list. See
        https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
        Default is `None`, mean that no ACL is applied to the object.
    cache_control : `str`, optional
        The cache-control header value. For example, ``'max-age=31536000'``.
    """
    logger = logging.getLogger(__name__)

    extra_args = {}
    if acl is not None:
        extra_args['ACL'] = acl
    if metadata is not None and len(metadata) > 0:  # avoid empty Metadata
        extra_args['Metadata'] = metadata
    if cache_control is not None:
        extra_args['CacheControl'] = cache_control

    # guess_type returns None if it cannot detect a type
    content_type, content_encoding = mimetypes.guess_type(local_path,
                                                          strict=False)
    if content_type is not None:
        extra_args['ContentType'] = content_type

    logger.debug(str(extra_args))

    obj = bucket.Object(bucket_path)
    # no return status from the upload_file api
    obj.upload_file(local_path, ExtraArgs=extra_args)
Upload a file to the S3 bucket.

    This function uses the mimetypes module to guess and then set the
    Content-Type and Encoding-Type headers.

    Parameters
    ----------
    local_path : `str`
        Full path to a file on the local file system.
    bucket_path : `str`
        Destination path (also known as the key name) of the file in the
        S3 bucket.
    bucket : boto3 Bucket instance
        S3 bucket.
    metadata : `dict`, optional
        Header metadata values. These keys will appear in headers as
        ``x-amz-meta-*``.
    acl : `str`, optional
        A pre-canned access control list. See
        https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
        Default is `None`, mean that no ACL is applied to the object.
    cache_control : `str`, optional
        The cache-control header value. For example, ``'max-age=31536000'``.