读取安卓本地docx 文件 转成ArrayBuffer,生成一堆数字(大佬看我转的对吗?)
export const readFile = (path) => {
return new Promise((reslove, reject) => {
plus.io.resolveLocalFileSystemURL(path,(entry)=> {
entry.file((file) => {
const fileReader = new plus.io.FileReader();
fileReader.onloadend = (e) => {
let s = e.target.result
s = s.replace(/^data:[^;]+;base64,/, '')
s = uni.base64ToArrayBuffer(s)
const int8array = new Int8Array(s);
reslove(int8array)
}
fileReader.readAsText(file);
fileReader.onerror = (error)=> {
reject(error)
}
})
},(error) => {
reject(error)
})
})
}
利用mammoth将res1 arrayBuffer 传入 转备转成html用来预览docx文件
mammoth.convertToHtml({arrayBuffer: res1}, options).then(function(result){
const html = result.value
console.log(html)
}).catch(function(err){
console.log(err)
})
报错:Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?
1