<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
File Upload
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.base64"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
Upload
<%
FileOutputStream fos = null;
try {
String imageString = request.getParameter("file");
imageString = imageString.substring("data:image/png;base64,".length());
byte[] contentData = imageString.getBytes();
byte[] decodedData = base64.getDecoder().decode(contentData);
String imgName = request.getServletContext().getRealPath("uploadFiles") + "\" + String.valueOf(System.currentTimeMillis()) + ".png";
out.println(imgName);
fos = new FileOutputStream(imgName);
fos.write(decodedData);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
fos.close();
}
}
%>