在小程序端,.js文件中,使用以下代码下载文件
wx.showLoading({
title: '下载中',
});
console.log("下载文件:",fileId);
wx.cloud.downloadFile({
fileID: fileId,
timeout: 30,
success: (result) => {
console.log("下载成功",result.tempFilePath);
wx.downloadFile({
url: "https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf", //源文件地址
filePath:wx.env.USER_DATA_PATH+'/{要更改的名称}.pdf', //指定的本地文件路径 一定要带文件后缀名 不然无法打开 wx.env.USER_DATA_PATH类似本地文件根目录
success(res) {
console.log(res)
let data = res.filePath;
wx.openDocument({
filePath: data,
showMenu: true //表示右上角是否有转发按钮
})
}
})
//已验证Android,iOS 都可更改
//使用FileSystemManager.rename() 模拟器 有权限进行写入等操作 Android,iOS 都无权限(已验证) 已放弃
},
fail: (res) => {
console.log("下载失败:",res);
wx.showToast({
title: res.errMsg,
icon:'error'
});
},
complete: (res) => {
wx.hideLoading();
},
})
微信小程序-wx.downloadFile()
最新推荐文章于 2024-08-02 00:07:06 发布