gpt4 book ai didi

amazon-s3 - boto 获取 md5 s3 文件

转载 作者:行者123 更新时间:2023-12-04 01:30:20 34 4
gpt4 key购买 nike

我有一个用例,我使用分段上传将数百个文件上传到我的 S3 存储桶。每次上传后,我需要确保上传的文件没有损坏(基本上检查数据完整性)。目前,上传文件后,我重新下载并计算md5在内容字符串上并将其与 md5 进行比较本地文件。所以像

conn = S3Connection('access key', 'secretkey')
bucket = conn.get_bucket('bucket_name')
source_path = 'file_to_upload'
source_size = os.stat(source_path).st_size

mp = bucket.initiate_multipart_upload(os.path.basename(source_path))
chunk_size = 52428800
chunk_count = int(math.ceil(source_size / chunk_size))

for i in range(chunk_count + 1):
offset = chunk_size * i
bytes = min(chunk_size, source_size - offset)
with FileChunkIO(source_path, 'r', offset=offset, bytes=bytes) as fp:
mp.upload_part_from_file(fp, part_num=i + 1, md5=k.compute_md5(fp, bytes))
mp.complete_upload()

obj_key = bucket.get_key('file_name')
print(obj_key.md5) #prints None
print(obj_key.base64md5) #prints None

content = bucket.get_key('file_name').get_contents_as_string()
# compute the md5 on content
这种方法很浪费,因为它使带宽使用量加倍。我试过
bucket.get_key('file_name').md5 
bucket.get_key('file_name').base64md5
但都返回无。
有没有其他方法可以实现 md5不下载整个东西?

最佳答案

是的
使用 bucket.get_key('file_name').etag[1 :-1]这样就可以在不下载其内容的情况下获取 key 的 MD5。

关于amazon-s3 - boto 获取 md5 s3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26415923/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com