1.小程序保存图片到手机
wx.downloadFile({
url: 'https://cdn.uviewui.com/uview/swiper/swiper3.png', //仅为示例,并非真实的资源
success(res) {
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
if (res.statusCode === 200) {
console.log(res);
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(res) {
wx.showToast({
icon: 'none',
title: "保存成功"
})
},
fail: function(err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err
.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err
.errMsg === "saveImageToPhotosAlbum:fail authorize no response"
) {
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,