真机用wx.openDocument预览文件报错?
真机用wx.openDocument预览文件报错 ,报错提示是 document viewer already starting [图片] let arr=fileUrl.split(".")
let fileExtName=arr[arr.length-1]
let randfile = new Date().getTime() + "." + fileExtName;
let newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;
console.log(newPath)
wx.downloadFile({
url: fileUrl,
filePath: newPath,
success: function (res) {
console.log(res)
let filePathNew=res.filePath
wx.openDocument({
filePath: filePathNew,
fileType:fileType,
showMenu: true,
success: function(res) {
console.log('打开文档成功');
},
fail: function(error) {
console.log('打开文档失败',error);
wx.showToast({
icon: 'none',
title: '打开文件失败'
});
}
})
},
fail: function (res) {
wx.hideLoading();
}
})