uniapp上传图片转base64码案例
upImg(){ var that = this; uni.chooseImage({ count: 6, //默认9 sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sourceType: ['album'], //从相册选择 success: function (res) { if(res.errMsg=='chooseImage:ok'){ console.log(res); console.log(res.tempFiles[0].path); that.urlTobase64(res.tempFiles[0].path); that.upimg = res.tempFiles[0].path; } } }); }, urlTobase64(url) { var that = this; uni.request({ url: url, method: 'GET', responseType: 'arraybuffer', success: res => { let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64 that.image_1920 = base64; base64 = 'data:image/jpeg;base64,'+base64; //不加上这串字符,在页面无法显示 console.log('base64->',base64); } }); },