async exportPDF(file) {
var that = this
uni.showLoading({
title: '正在下载'
});
uni.downloadFile({
// url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-7da443bc-353a-4224-ab27-b98917aa6c66/89d1d612-734a-4219-9110-0b21fb004d5f.pdf",
url: file,
success: res => {
console.log(res)
if (res.statusCode === 200) {
uni.hideLoading();
// 保存pdf文件至手机,一般安卓端存储路径为:手机存储/dcim/camera文件夹下
uni.saveFile({
tempFilePath: res.tempFilePath, //临时路径
success: function(res1) {
console.log('打印res', res1)
uni.$u.toast(`文件下载成功`);
//自动打开文档查看
setTimeout(() => {
var filePath = res1.savedFilePath;
uni.openDocument({ //新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
filePath: filePath,
showMenu: true,
success: function(res11) {
console.log('打开文档成功');
}
});
}, 2000)
}
});
}
},
fail: function(res) {
uni.showToast({
title: "文件下载失败",
icon: 'error',
duration: 3000,
})
},
})
},
uniapp前端实现下载已知路径的文件
于 2023-08-31 18:03:26 首次发布