Get the App
SLTechnology News&Howtos  ›  Development  › 

How to save WeChat Mini Programs's pictures

Shulou Source: shulou.com Published: 2022-06-01 00:21:35 09月21日 Update

本篇内容介绍了"微信小程序图片怎么保存"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

具体操作步骤:

1.下载文件资源到本地:客户端直接发起一个 http get 请求,返回文件的本地临时路径。

即:调用函数wx.downloadfile({})

2.保存图片到系统相册。

即:调用函数wx.saveimagetophotosalbum({})

具体代码如下:

.wxml

保存图片

.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({

title: "保存成功",

})

}, fail: function (res) {

wx.showtoast({

title: "保存失败",

})

}

})

}

},

})

},

"微信小程序图片怎么保存"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

Tags: Pictures programs content functions files more knowledge paths practicality success learning next code dilemma reality client client situation article server Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology Redmi Apple Shulou Information