zoukankan      html  css  js  c++  java
  • 前端通过本地文件路径获取该文件Buffer

    onFileChange = e => {
        ...
    
        const reader = new FileReader();
        reader.readAsArrayBuffer(e.target.files[0], 'utf-8'); //发起异步请求
        reader.onload = function () {
          //读取完成后,数据保存在对象的result属性中
          const buffer = new Uint8Array(this.result)
          // console.log('buffer:', buffer)
          getEtag(buffer, eTag => { // 获取七牛云fileHash
            console.log('eTag:', eTag)
            const { infoVO: { imId: loginImId = '' } = {} } = storage.get('user') || {}
            const custom = { // 配合移动端扩展字段
              sessionID: scene === 'p2p' ? loginImId : to,
              sessionType: scene === 'p2p' ? 0 : 1
            }
            let options = {
              scene,
              to,
              type,
              fileInput: 'uploadFile',
              custom: JSON.stringify(custom),
              done: () => {
                that.buildSessions()
              }
            }
            if (type === 'file') { // 文件类型添加扩展字段fileHash
              options = {
                ...options,
                custom: JSON.stringify({
                  fileHash: eTag,
                  ...custom
                }),
              }
            }
            nim.sendFile(options)
          })
        }
      }
  • 相关阅读:
    HDU4112
    HDU1059 二进制拆分优化多重背包
    HDU1087
    HDU1978How Many Ways 记忆化dfs+dp
    HDU1160FatMouse's Speed
    HDU1503Advanced Fruits
    CF337C
    337BRoutine Problem
    【★★★★★模板专区★★★★★】
    【水】Jam计数法
  • 原文地址:https://www.cnblogs.com/LP1204/p/12108193.html
Copyright © 2011-2022 走看看