uniapp图片文件转base64
fileUpload() {
let _this = this;
uni.chooseImage({
count: 1,
success: res => {
this.urlTobase64(res.tempFilePaths[0]);
}
})
},
// 获取图片信息
urlTobase64(url){
uni.request({
url: url,
method: 'GET',
responseType: 'arraybuffer',
success: res => {
let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64
base64 = 'data:image/jpeg;base64,' + base64; //不加上这串字符,在页面无法显示
console.log(base64);
}
});
},