@NotNull
private String base64ToImageAndSaveLocal(String base64Image, String imageName) {
File folder = new File(folderPath);
if (!folder.exists()) {
boolean created = folder.mkdirs();
if (created) {
log.info(folderPath+" 目录创建成功");
} else {
throw new CustomException(folderPath+" 目录创建失败");
}
}
String imgName = imageName +"-"+System.currentTimeMillis()+".jpg";
String absolutePath = folderPath +imgName;
try {
if(base64Image.contains("base64")){
base64Image = base64Image.substring(base64Image.indexOf("base64,")+7);
}
byte[] imageData = Base64.decode(base64Image);
FileOutputStream imageOutFile = new FileOutputStream(absolutePath);
imageOutFile.write(imageData);
imageOutFile.close();
} catch (Exception e) {
throw new CustomException("识别图片存储错误:" + e.getMessage());
}
return imgName;
}