//下载文件
downLoadFile(){
/*var fileUrl = this.content.enclosureUrl; var url =decodeURIComponent(fileUrl);//对 encodeURIComponent() 函数编码的 URI 进行解码 var reg = new RegExp(":443"); url = url.replace(reg,"");*/
//下载文件,生成临时地址
uni.showLoading({
title: '下载中...',
})
uni.downloadFile({
url: url,
success(res) {
//保存到本地
uni.saveFile({
tempFilePath: res.tempFilePath,
success: function (res) {
const savedFilePath = res.savedFilePath;
// 打开文件
uni.openDocument({
filePath: savedFilePath,
success: function (res) {
uni.hideLoading()
},
});
},
fail: function (err) {
uni.hideLoading();
uni.showLoading({
title: '保存失败',
})
}
});
},
fail(res) {
uni.hideLoading();
uni.showLoading({
title: '下载失败',
})
}
})
}
uniapp 文件下载保存并打开
原文作者:前端菜鸟丶Ndie
原文地址: https://blog.csdn.net/m0_46978096/article/details/116480621
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/m0_46978096/article/details/116480621
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。