目前小程序要做保存excel、pdf等文件的功能,
我调用了wx.downFile,然后再调用saveFile,直接是走进了saveFile的success函数,但是保存的文件去哪里打开呢,还是说这个保存并不是保存到手机上?
还是说,现在的小程序并不支持保存文件到手机上(不是临时保存,是可以在退出小程序后再次在手机中找到并且打开)
wx.downloadFile({
url: item.url,
// filePath: wx.env.USER_DATA_PATH + '/' + item.fullName,
success (res) {
if (res.statusCode === 200) {
wx.hideLoading()
// let tempFilePath = res.filePath // 如果设置了filePath参数,则不会有tempFilePath
let tempFilePath = res.tempFilePath
wx.saveFile({
tempFilePath,
success (res) {
// 可以进行到这里
console.log(res);
const savedFilePath = res.savedFilePath
wx.showToast({
title: '下载成功',
icon: 'none',
mask: true
})
},
fail (err) {
console.log(err);
wx.showToast({
title: '下载失败,请重新尝试',
icon: 'none',
mask: true
})
}
})
}
}
})
请问ios也有保存到手机这一项吗?
已经找到方法可以保存到手机了~
保存在了微信临时目录里,并不在系统目录下,所以通过系统并不能直接访问到通过接口下载的文件。
保存以后不是可以获取到保存后的地址,这个可以重复使用,顺便提一下小程序保存文件不能超过10M,而且大的文件保存了也容易被回收掉。