1,后端返回的是图片数据流,格式如下
���� JFIF ��C 如何把这样的文件流转化为base64,
btoa是浏览器提供的函数,但在 小程序 环境中(如微信小程序、支付宝小程序),btoa不可用。你需要手动编写 Base64 编码逻辑或者使用第三方库
2,uniapp调用接口
export async function getImgFn(objectKey,md5){
const res =await uni.request({
url:ip地址,
header: {
'VerificationToken': 12, //请求头根据你的要求传,我这里没有要求
},
method: "GET",
responseType: 'arraybuffer',
});
let base64img='data:image/jpeg;base64,' + base64Encode(res.data) //手动写一个base64Encode方法
return base64img;
}
3,手动写一个base64Encode数据流转base64方法
function base64Encode(buffer) {
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
let base64 = '';
let padding = '';
let remainder = binary.length % 3;
if (remainder > 0) {
for (let i = 0; i < 3 - remainder; i++) {
padding += '=';
binary += '\0';
}
}
for (let i = 0; i < binary.length; i += 3) {
const n = (binary.charCodeAt(i) << 16) |
(binary.charCodeAt(i + 1) << 8) |
binary.charCodeAt(i + 2);
base64 += base64Chars[(n >> 18) & 63] +
base64Chars[(n >> 12) & 63] +
base64Chars[(n >> 6) & 63] +
base64Chars[n & 63];
}
return base64.substring(0, base64.length - padding.length) + padding;
}
![电脑问题4[非华为电脑安装华为电脑管家华为荣耀手机多屏协助]](https://i-blog.csdnimg.cn/direct/5dde911f252948238abcc45f10e3e0be.png)


![[数据结构] 链表](https://i-blog.csdnimg.cn/direct/af54ec2d91de426cafec78bbb69f6d90.png)








![[react] <NavLink>自带激活属性](https://i-blog.csdnimg.cn/direct/e2c27d6096084ef38bb15334a2385c42.png)






