nodeJs实现微信小程序的图片上传

今天我来介绍一下nodejs如何实现保存微信小程序传过来的图片及其返回

首先wx.uploadFile绝大部分时候是配合wx.chooseImage一起出现的,毕竟选择好了图片,再统一上传是实现用户图片上传的正常逻辑。

1 //添加图片 2 addImg: function() { 3 var that = this; 4 console.log(9 - that.data.checkImgLength) 5 if (9 - that.data.checkImgLength >= 1){ 6 wx.chooseImage({ 7 count: 9 - that.data.checkImgLength, // 默认9 8 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 9 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 10 success: function (res) { 11 var tempFilePaths = res.tempFilePaths//这里拿到的是图片在微信客户端的临时路径!!! 12 let length = tempFilePaths.length; 13 let tempList = that.data.imgLists.concat(tempFilePaths);//JSON数据 14 that.setData({ 15 imgLists: tempList, 16 checkImgLength: that.data.checkImgLength + length//长度相加,这里是为了选择的图片不会超过9 17 }) 18 } 19 }) 20 } 21 },

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wspzxf.html