上傳圖片/視頻含有大量重復的解決辦法


上傳圖片/視頻含有大量重復

思路:獲取圖片/視頻的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)
          }
        })
      }
    })
  },

image
參考文檔:SparkMD5地址:MD5算法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM