String img64 = base64Encode(bytes);
String img642 = base64.normalize(img64);
String img6421 = "data:image/jpg;base64,${base64.normalize(img64)}";
iam 尝试将图像转换为 Base64,但它被转换为后端服务器不接受的不同字符串 在此链接中图像正在工作https://codepen.io/jamiekane/pen/YayWOa 但是当测试颤振输出时它不起作用
String img64 = base64Encode(bytes);
String img642 = base64.encode(img64).replaceAll('/', '_').replaceAll('+', '-'); String img6421 = "数据:image/jpg;base64, $img642";
看起来 Base64 编码的标准化方式存在一些差异。不要使用
base64.normalize(img64)
,而是尝试使用 base64.encode(img64).replaceAll('/', '_').replaceAll('+', '-')
正确编码 Base64 字符串。
这应该会生成一个格式正确的 base64 字符串,您的后端服务器可以接受该字符串。