小程序上传base64的图片,可上传多张

微信小程序上传图片转化为base64格式

clickimage: function(e) {
var index = e.currentTarget.dataset.index;
var count = 4;
var that = this;
wx.chooseImage({
count: count,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success(res) {
var tempFilePaths = res.tempFilePaths;
for (var x = 0; x < res.tempFilePaths.length; x++) {
wx.getFileSystemManager().readFile({
filePath: res.tempFilePaths[x], //选择图片返回的相对路径
encoding: "base64",//这个是很重要的
success: res => { //成功的回调
//返回base64格式
console.log('data:image/png;base64,' + res.data)
}
})
}
}
})
},

原文地址:https://www.cnblogs.com/gavinjay/p/11732869.html