Boto3 / S3 / Django:在计算文件哈希时避免阻塞事件循环

问题描述 投票:1回答:1

从gunicorn + gevent worker,通过django-storages将(多部分)上传到S3,如何确保在计算文件/部件内容的散列期间,事件循环不被阻止?

查看source for django-storages,似乎没有任何传递md5(/另一个哈希)的空间,并且在source for botocore中似乎没有在计算哈希值时产生事件循环的范围。

django amazon-s3 boto3 gunicorn gevent
1个回答
0
投票

现在有一个PR for django-storages that calculates the MD5 hash as data received by the application

总之,这会改变S3Boto3StorageFile以及init和new part

self._file_md5 = hashlib.md5()

然后收到content_bytes

self._file_md5.update(content_bytes)

然后当上传每个部分时,ContentMD5参数被传递给部件上传功能

ContentMD5=base64.b64encode(self._file_md5.digest()).decode('utf-8')
© www.soinside.com 2019 - 2024. All rights reserved.