const downloadPublic = (attachLink,fileType) => {
let that = this
let filePath = uni.env.USER_DATA_PATH+'/'+ decodeURIComponent(getFileNameByPath(attachLink))
uni.downloadFile({
url: attachLink , //下载地址,后端接口获取的链接
success: (res) => {
if (res.statusCode === 200) {
uni.getFileSystemManager().saveFile({ //文件保存到本地
tempFilePath: res.tempFilePath, //临时路径 data.tempFilePath
filePath:filePath,
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存!',
duration: 3000,
});
uni.openDocument({
fileType: fileType,
showMenu:true, //关键点,可以转发到微信
filePath: res.savedFilePath,
success: function(res) {
console.log('打开文档成功');
}
});
}
});
}
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
}
uniapp 通用下载文件方法并可以重命名文件
最新推荐文章于 2025-03-29 15:22:58 发布