原方法
uni.downloadFile({
url: pdfURL, // 文件原本 URL 地址
success(res) {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath, // 微信临时文件路径
showMenu: true // 右上角是否有可以转发分享的功能(只支持微信小程序)
});
}
}
});
新方法
uni.downloadFile({
url: pdfURL, // 文件原本 URL 地址
filePath: uni.env.USER_DATA_PATH + "/" + "考察文件.pdf", // 需要预览文件的名称
success(res) {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.filePath, // 微信临时文件路径
showMenu: true // 右上角是否有可以转发分享的功能(只支持微信小程序)
});
}
}
});
在 downloadFile 方法中添加 filePath: uni.env.USER_DATA_PATH + '/' + '文件名.pdf' 即可