Illegal base64 character 3a

这个问题一般都是转译的问题。或者在写decode的时候写成了file.byte[]。

base64后 前缀 是 “data:image/png;base64,” 类似这样的。需要去掉,并且替换回车和换行符

if (file.contains("data:")) {
    int start = file.indexOf(",");
    file = file.substring(start + 1);
}

final Base64.Decoder decoder = Base64.getDecoder();
file = file.replaceAll("\r|\n", "");
file = file.trim();
byte[] bytes = decoder.decode(file);

这样写基本可以解决这个问题

————————————————
版权声明:本文为CSDN博主「LeeShaoQing」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43040108/article/details/114219325

posted on 2023-11-01 15:57  天军  阅读(540)  评论(0编辑  收藏  举报

导航