uni-app
项目中用到,非常有用:uniapp做H5项目渲染后端接口返回的图片流_uniapp h5后端返回文件流转图片-CSDN博客
留个记录:
uni.request({
url: '*****',
method: 'GET',
responseType: 'arraybuffer',
header: {
"Authorization": '*****'
},
success: res => {
let datas = res.data;
// #ifdef H5
this.qrcodeUrl = 'data:image/png;base64,' + btoa(new Uint8Array(datas).reduce((datas,
byte) => datas + String.fromCharCode(byte), ''));
// #endif
// #ifdef MP
this.qrcodeUrl = 'data:image/png;base64,' + uni.arrayBufferToBase64(data);
// #endif
},
});