網站首頁 編程語言 正文
按道理來說,不同的圖片應該具有不同的md5,但是在測試的時候發現上傳不同的圖片md5總是一樣的。
看看代碼:
handleFileChange(file) {
console.log(file) // 變化的文件對象
const reader = new FileReader()
reader.readAsDataURL(file.raw)
var Spark = new SparkMD5.ArrayBuffer()
const that = this
reader.onload = function(event) {
const img_base64 = event.target.result
console.log(img_base64)
that.basic_config_info.logo_stream = img_base64
Spark.append(event.target.result)
var md5 = Spark.end()
console.log('md5')
console.log(md5)
if (that.basic_config_info.logo_md5 === md5) {
console.log('相等')
} else {
console.log('不相等')
}
that.basic_config_info.logo_md5 = md5
}
},
我既要獲取到圖片的base64也要獲取到md5,而reader.readAsDataURL(file.raw)
用來獲取base64,如果用來獲取md5,就會出現相同的md5,正確獲取md5應該使用reader.readAsArrayBuffer(file.raw)
所以應該設置兩個不同的reader來分別獲取base64和md5
下面是正確的代碼:
handleFileChange(file) {
console.log(file) // 變化的文件對象
const stream_reader = new FileReader()
const md5_reader = new FileReader()
stream_reader.readAsDataURL(file.raw)
md5_reader.readAsArrayBuffer(file.raw)
const that = this
stream_reader.onload = function(event) {
const img_base64 = event.target.result
console.log(img_base64)
that.basic_config_info.logo_stream = img_base64
}
md5_reader.onload = function(event) {
var Spark = new SparkMD5.ArrayBuffer()
Spark.append(event.target.result)
var md5 = Spark.end()
console.log('md5')
console.log(md5)
that.basic_config_info.logo_md5 = md5
}
},
然后上傳不同的圖片,就會發現具有不同的md5啦!
原文鏈接:https://blog.csdn.net/changyana/article/details/130974501
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-08-17 React-Route6實現keep-alive效果_React
- 2022-04-01 Kubeadm:如何解決kubectl get cs顯示scheduler Unhealthy,co
- 2022-06-02 Go語言數據類型詳細介紹_Golang
- 2023-04-19 Invalid prop: custom validator check failed for pr
- 2023-11-17 Python 如何獲取線程的返回值
- 2022-02-11 tomcat?logs?目錄下各日志文件的解析(小結)_Tomcat
- 2022-12-04 python?使用enumerate()函數詳解_python
- 2022-09-03 Go語言中的變量和常量_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支