public String uplaodByte(HttpServletRequest request, HttpServletResponse response, String base64ImgData) {
JSONObject result = new JSONObject();
try {
String path = "/QRCodePoster/";
String fileName = "poster_img.png";
//获取项目绝对路径
String realPath = request.getSession().getServletContext().getRealPath("/");
realPath = realPath.replaceAll("\\\\", "/");
String userPath = realPath + path;
File dirFile = new File(userPath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
File file = new File(userPath, fileName);
if (!file.exists()) {
file.createNewFile();
}
Base64 d = new Base64();
byte[] bs = d.decode(base64ImgData);
FileUtils.writeByteArrayToFile(file, bs);
return path + fileName;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
需要到一个hutool-all-4.1.19.jar的jar包