默认的 uni.downloadFile会返回tempFilePath,返回格式安卓为bin后缀。
如:
// An highlighted block
uni.downloadFile({
url: xxxxxxxxxx,
success: (data) => {
if (data.statusCode === 200) {
uni.openDocument({
filePath: data.tempFilePath, // 临时路径为bin后缀
fileType: fileName.split('.')[1], // 文件类型
showMenu: true, // 是否展示分享
success: function (res) {
uni.hideLoading()
}
})
}
},
更改:
// An highlighted block
uni.downloadFile({
url: xxxxxxxxxx,
filePath: wx.env.USER_DATA_PATH + '/' + fileName, // 定义一个路径 fileName === 例如:xxx.pdf/doc 等等
success: (data) => {
if (data.statusCode === 200) {
uni.openDocument({
filePath: data.filePath,
fileType: fileName.split('.')[1], // 文件类型
showMenu: true, // 是否展示分享
success: function (res) {
uni.hideLoading()
}
})
}
},