如何将图片转为base64,然后进行 request请求
发布于 5 年前 作者 guiyinglai 15979 次浏览 来自 问答

如何将图片转为base64,然后进行 request请求

3 回复

您可以将图片文件以 base64 形式读出,再进行使用。

wx.chooseImage({

count:1,

success: function(res) {

console.log(res.tempFiles[0].path);

wx.request({

url: res.tempFiles[0].path,

method:‘get’,

responseType:‘arraybuffer’,

success:function(data){

var base64=wx.arrayBufferToBase64(data.data);

base64 =“data:image/png;base64,”+base64;

base64=encodeURIComponent(base64);

console.log(base64);

wx.request({

url: https://www.mydomain.com/Handler/Base64ImageHandler.ashx,

method:‘post’,

header: { ‘content-type’:‘application/x-www-form-urlencoded’},

data: “imgurl=”+base64,

success:function(db){

console.log(db.data);

}

})

}

})

}

})

这样的方法  是可以得出图片转换为base64   可以在网上的在线工具显示出来,,,目前我测试的只能在微信web开发工具上有效,但是在手机上就没有效果了 直接抛出异常了,,,

回到顶部