第一种,普通图片路径
uni.downloadFile({
url: this.yaoqinphoto,
success: (res) => {
console.log(res)
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.showToast({
title: '保存成功',
icon: 'none'
})
},
fail(err) {
uni.showToast({
title: '下载失败',
icon: 'none'
})
}
})
},
fail(err) {
console.log(err)
}
});
第二种,图片是 base64
// 图片是base64
let base64=this.yaoqinphoto.replace(/^data:image\/\w+;base64,/, "");//去掉data:image/png;base64,
let filePath=wx.env.USER_DATA_PATH + '/hym_pay_qrcode.png';
uni.getFileSystemManager().writeFile({
filePath:filePath , //创建一个临时文件名
data: base64,
encoding: 'base64', //写入当前文件的字符编码
success: res => {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success: function(res2) {
uni.showToast({
title: '保存成功,请从相册选择再分享',
icon:"none",
duration:5000
})
},
fail: function(err) {
uni.showToast({
title: '下载失败',
icon: 'none'
});
}
})
},
fail: err => {
//console.log(err)
uni.showToast({
title: '下载失败',
icon: 'none'
});
}
})