前端切割base64字符
function ObtainImageUploadLocation(commentSuggestionForReview) {
//切割字符串 获取字符
var split = commentSuggestionForReview.split("\"");
var img = "";
//循环字符串 通过indexof判断是否有img和src 以及下一个下一个img当中是否有base64当中有的data:image的标签
for (var i = 0; i < split.length; i++) {
if (split[i].indexOf("<img") != -1 && split[i].indexOf("src=") != -1 && split[i + 1].indexOf("data:image") != -1) {
var param = {
commentSuggestionForReview: split[i + 1]
}
//调用接口 通过后端转换为指定的url地址
uuwatchAjax(param, url, false,function (review) {
if (review.success == true) {
img = img + split[i] + review.url
}
});
i = i + 1
} else {
img += split[i];
}
}
return img;
}
//后端转换base64代码
try {
BASE64Decoder decoder = new BASE64Decoder(); //转换
byte[] decoderBytes = decoder.decodeBuffer('前端传递值');
//图片位置
String targetPath = 'G:\aa.png'
FileOutputStream out = new FileOutputStream(targetPath);
out.write(decoderBytes);
} catch (Exception e) {
e.printStackTrace();
}