// 下载
download(url) {
const { detail } = this.data
//初始化指定文件下载后存储的路径
let filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4'
console.log('new Date().valueOf()',filepath)
let method = detail.materialType == 2 ? 'saveVideoToPhotosAlbum' : 'saveImageToPhotosAlbum'
return new Promise((resolve, reject) => {
wx.downloadFile({
url: url,
filePath: filepath,
success: function (res) {
var temp = res.tempFilePath
if (res.statusCode === 200) {
wx[method]({
filePath: temp,
success: function (res) {
resolve(res)
},
fail: function (err) {
wx.showToast({ title: '保存失败' })
console.log(err, '下载失败===>', res)
reject(err)
}
})
}
},
fail: function (err) {
console.log('err===>',err)
reject(err)
}
})
})
},
/**/ let filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4' // 加上临时路径 会报 saveVideoToPhotosAlbum:fail get file path fail?
去掉 let filepath = wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4' 会被报 saveVideoToPhotosAlbum:fail invalid video
临时路径不存在,检查代码
不是成功了吗? 权限问题?