上傳圖片/視頻含有大量重復
思路:獲取圖片/視頻的MD5值 傳到后台進行比較
下邊以微信小程序為例:
一、引入spark-md5.min.js
const sMD5 = require('../../utils/spark-md5.min.js')
二、選擇圖片/視頻 獲取文件
addimage: function (e) {
var that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success (res) {
let filePath = res.tempFilePaths[0]
wx.getFileSystemManager().readFile ({
filePath: res.tempFilePaths[0],
success: res => {
let spark = new sMD5.ArrayBuffer();
spark.append(res.data);
let hexHash = spark.end(false);
that.setData({
md5: hexHash,
src: filePath,
flag: false
})
console.log(hexHash)
}
})
}
})
},
參考文檔:SparkMD5地址:MD5算法