//保存视频
handleDownload() {
wx.showLoading({
title: '下载中',
mask:true
})
let fileName = new Date().valueOf();
wx.downloadFile({
url: "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400",
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
success: res => {
console.log(res)
wx.hideLoading()
let filePath = res.filePath; //下载到本地获取临时路径
let fileMgr = wx.getFileSystemManager();
wx.saveVideoToPhotosAlbum({ //保存到相册
filePath,
success: file => {
console.log(file)
wx.showToast({
title: '视频保存成功',
duration:3000,
icon:'none'
})
fileMgr.unlink({ //删除临时文件
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
})
},
fail: err => {
console.log(err)
fileMgr.unlink({ //删除临时文件
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.mp4',
})
wx.showToast({
title: '视频保存失败',
duration:3000,
icon:'none'
})
},
complete() {
wx.hideLoading()
}
})
},
fail(e) {
wx.showToast({
title: '视频保存失败',
duration:3000,
icon:'none'
})
},
complete() {
// wx.hideLoading();
}
})
},
//获取用户授权
onStartDownload() {
wx.getSetting({
success:(res)=> {
if (res.authSetting['scope.writePhotosAlbum'] === undefined) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success:()=> {
console.log('打开了授权')
this.handleDownload()
},
fail:(err)=> {
}
})
} else if (!res.authSetting['scope.writePhotosAlbum']) {
wx.openSetting({
success:(res)=> {
console.log(res)
if (res.authSetting['scope.writePhotosAlbum']) {
console.log('授权了')
this.handleDownload()
} else {
}
},
fail:(err)=> {
},
})
} else {
this.handleDownload()
}
}
})
},
报错内容:errMsg: "saveVideoToPhotosAlbum:fail ENOENT: no such file。
ios 与安卓系统真机调试没有问题,但是真机预览保存失败。
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
建议检查一下downloadFile合法域名是不是有问题?