s3_utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:dependencies-resolver 作者: onfido 项目源码 文件源码
def get_object_md5_checksum(bucket, key):
    """This function returns the MD5 checksum for the remote file.
    If the file was uploaded as a single-part file, the MD5 checksum will be
    the checksum of the file content.
    However, if the file was uploaded as multi-part file,
    AWS is calculating the MD5 the following way (Based on AWS documentation):
        1. Calculate the MD5 md5_hash for each uploaded part of the file.
        2. Concatenate the hashes into a single binary string.
        3. Calculate the MD5 md5_hash of that result.
        4. Concatenate the resulted MD5 md5_hash with a dash
           and number of file parts.

    :param bucket: The name of the bucket.
    :param key: The full path to the remote file.
    :return: The MD5 checksum for the remote file.
    """
    try:
        md5_checksum = s3_client.head_object(
            Bucket=bucket,
            Key=key
        )['ETag'][1:-1]
    except botocore.exceptions.ClientError:
        md5_checksum = ''
    return md5_checksum
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号