上传图片/视频含有大量重复
思路:获取图片/视频的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算法