django - Boto3/S3/Django:在计算文件哈希时避免阻塞事件循环
问题描述
从 gunicorn+gevent 工作人员,通过django- storages 进行(多部分)上传到 S3 ,如何确保在计算文件/部分内容的哈希期间,事件循环不被阻塞?
查看 django-storages的源代码,实际上似乎没有任何传递 md5(/另一个哈希)的范围,并且在botocore 的源代码中似乎没有产生事件循环的范围,而正在计算哈希。
解决方案
现在有一个用于 django-storages 的 PR,它计算 MD5 哈希作为应用程序接收到的数据。
总之,这改变S3Boto3StorageFile
了 init 和 new 部分
self._file_md5 = hashlib.md5()
然后收到content_bytes
self._file_md5.update(content_bytes)
然后在每个part上传时,将ContentMD5
参数传递给part upload函数
ContentMD5=base64.b64encode(self._file_md5.digest()).decode('utf-8')
推荐阅读
- ravendb - 使用通配符在字符串数组字段中搜索 RavenDb 方面
- java - Google Calendar Events Watch 401 未经授权
- c# - 通过 REST 服务更新记录
- php - 从文本文件中删除一些字符串
- delphi - Delphi FastReports - 如何更改行?
- python - 数据转换/准备
- c - 在 setjmp() + longjmp() 之间传递比“int”更多的数据
- html - 为什么输入和按钮不占用 div 的整个宽度?
- c++ - 使用宏简化 C++ 代码。错误:粘贴“<”和“字符串”不会给出有效的预处理标记
- excel - 如何随机化excel单元格中的值?