Base64文件下载
String[] split = strBase64.split("base64,");
ServletOutputStream out = null;
byte[] b = null;
String str = "";
try {
out = response.getOutputStream();
if ("data:image/jpg;".equals(split[0])) {
LOGGER.info("图片base64");
response.setContentType("image/jpeg");
b = Base64.decode(split[1]);
str = ".jpg";
} else {
LOGGER.info("pdf base64");
response.setContentType("application/pdf");
b = Base64.decode(split[1]);
str = ".pdf";
}
String fileName = "下载文件名"+ str;
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''"
.concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
out.write(b);
} catch (IOException exception) {
exception.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException exception) {
exception.printStackTrace();
}
}
}