// 将File转成 Buffer,在 aliyun-oss环境中
function readFileAsBuffer(file) {
const reader = new FileReader()
return new Promise((resolve, reject) => {
reader.addEventListener('loadend', () => {
const base64File = reader.result.replace(/^data:\w+\/\w+;base64,/, '')
resolve(new OSS.Buffer(base64File, 'base64'))
})
reader.readAsDataURL(file)
})
}
网友评论