//url=https://xxxx.pdf
wx.request({
url: url,
data:data,
responseType:"arraybuffer",
success (res) {
if(res.header["Content-Type"].indexOf("application/pdf")!=-1){
var save = wx.getFileSystemManager();
let pdfname='aaaa.pdf'
let filePath = wx.env.USER_DATA_PATH + '/' + pdfname;
save.writeFile({
filePath: filePath,
data: res.data,
success: res => {
console.log("bbbbb", res);
wx.openDocument({
filePath: filePath ,
showMenu:"true",
fileType:"pdf",
success: function (res) {
console.log('open doc success')
},
fail: function (res) {
clearInterval(icount)
console.log('open doc failed',res);
},
complete: function (res) {
wx.hideLoading();
}
})
}
})
}
}
})
|