 
		Karory
2019-11-08 02:46
wx.chooseImage 成功后返回的地址是这样的:"http://tmp/wxf75b856db0af7416.o6zAJs2y9meeapWKOCO0bNGHD33g.COls47yvj9yP627957ccd7ee173198020191d011e6b3.jpg"
能转换成二进制吗?如何转?因为想要调用百度api的人脸识别接口,需要传入图片的二进制转base64格式
 
				在云函数中转:
new Buffer()
 
				还查找到了一种在小程序端实现的:
wx.chooseImage({
      success: res => {
      wx.getFileSystemManager().readFile({
          filePath: res.tempFilePaths[0], //选择图片返回的相对路径
          encoding: 'base64', //编码格式
          success: res => { //成功的回调
            console.log('data:image/png;base64,' + res.data)
          }
        })
//以下两行注释的是同步方法
        //let base64 = wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], 'base64') 
        //console.log(base64)
      }
    })轻松入门微信小程序与云开发
64634 学习 · 1742 问题
相似问题