python - 从文件 md5 和文件名中生成一致的 uuid,如哈希
问题描述
我有来自发布 http 请求的文件内容和名称,我想8fa14cdd754f91cc6554c9e71929cce7
从文件名和文件 md5中取名
解决方案
可以用下一个代码来完成
content_hash_md5 = md5() # noqa: S303
content_hash_md5.update(file_bytes)
content_hash_md5.update(file_name.encode())
base, ext = os.path.splitext(file_name)
new_name = content_hash_md5.hexdigest() + ext
with open(new_name, "wb") as fd:
fd.write(file_bytes)
推荐阅读
- java - H2 导致 org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException 而 Hibernate 不会
- javascript - 如何使用jquery检查是否有人滚动到元素
- oracle - ADB 上允许的最大会话数是多少?有可能改变它吗?
- python - 如何将列名转换为 Pandas 中的值
- linux - Bash - 查找包含特定日志文件的目录
- bytecode - 字节码命令是否对齐?
- flutter - 如何使用 showModelBottomSheet 创建 DraggableScrollableSheet?
- linux - 如何使用awk将特定列中的数字替换为另一个数字
- javascript - stripe.redirectToCheckout 中的“结果对象”是什么?
- r - R:测试多元回归中不同方程的系数是否相等(使用线性假设())?