⼩程序保存图⽚⾄相册(解决saveimagetophotosalbum:
failinv。。。
const that = this
let fileName = new Date().valueOf();
let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg'
wx.downloadFile({
url: srcUrl,//此处为接⼝返回的图⽚地址
filePath: filePath,
success: function (res) {
// 保存图⽚到系统相册
wx.saveImageToPhotosAlbum({
filePath: filePath,
success(data) {
let fileMgr = wx.getFileSystemManager()
fileMgr.unlink({
filePath: filePath,
success(){
console.log(222);
}
})
},
fail(data){
Msg === "saveImageToPhotosAlbum:fail:auth denied" || Msg === "saveImageToPhotosAlbum:fail auth deny" || Msg === "saveImageToPhotosAlbum:fail authorize no response") {
wx.showModal({
title: '提⽰',
content: '需要您授权保存相册',
showCancel: false,
success: modalSuccess => {
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {getsavefilename
console.log('获取权限成功,给出再次点击图⽚保存到相册的提⽰。')
}else {
console.log('获取权限失败,给出不给权限就⽆法正常使⽤的提⽰')
}
}
})
}
})
}
}
})
},
fail: function (res) {
}
})
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论