rd = request.getRequestDispatcher("P-Upload.jsp");
rd.forward(request, response);
return;
}
Part filePart = request.getPart("btnSelectFile");
if (!this.checkImageExtension(filePart)) {
request.setAttribute("uploadPhotoMessage", "Alleen foto's met een jpg/jpeg of png extensie mogen worden geüpload.");
request.setAttribute("messageColor", "red");
rd = request.getRequestDispatcher("P-Upload.jsp");
rd.forward(request, response);
return;
}
String fileExtension = filePart.getContentType().split("/")[1].toLowerCase();
Integer filename = DatabaseKoppeling.getNextPhotoName();
if (filename != null) {
String location = String.format("%s%s.%s", getServletContext().getInitParameter("PhotoLocation"), filename, fileExtension);
File photo = new File(String.format("%s%s.%s", getServletContext().getInitParameter("PhotoLocation"), filename, fileExtension));
BufferedInputStream input = null;
OutputStream output = null;
try {
long processedBytes = 0;
int lastProgress = 0;
input = new BufferedInputStream(filePart.getInputStream());
output = new FileOutputStream(new File(location));
while (input.available() > 0) {
output.write(input.read());
processedBytes++;
int progress = (int)(100 * ((double)processedBytes / (double)filePart.getSize()));
if (lastProgress != progress) {
lastProgress = progress;
System.out.println(progress);
}
}