網站首頁 編程語言 正文
按道理來說,不同的圖片應該具有不同的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-04-28 C#圖形編程GDI+基礎介紹_C#教程
- 2022-05-07 Python中list列表的賦值方法及遇到問題處理_python
- 2023-09-12 spring webflux配置成tomcat的線程池
- 2022-07-21 CUICatalog: Invalid asset name supplied: ‘‘
- 2022-06-29 Python容器類型轉換的3種方法實例_python
- 2022-11-19 Compose?動畫藝術之屬性動畫探索_Android
- 2023-05-20 Python?seek()和tell()函數的具體使用_python
- 2022-10-31 Kotlin類的繼承實現詳細介紹_Android
- 欄目分類
-
- 最近更新
-
- 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同步修改后的遠程分支