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)
})
}
}