微信小程序保存图片分为两步:
1.下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。
即:调用函数wx.downloadFile({})
2.保存图片到系统相册。
即:调用函数wx.saveImageToPhotosAlbum({})
具体代码如下:
.wxml
<button data-image='{ {图片路径}}' bindtap="saveImage" >保存图片</button>
.js
saveImage: function (e) {
wx.downloadFile({
url: 服务器Http请求 +图片路径,
success: function (res) {
var imageFilePath = res.tempFilePath;
if (!util.isNull(imageFilePath)) {
wx.saveImageToPhotosAlbum({
filePath: imageFilePath,
success: function (data) {
wx.showToast({