4afee607 by Ean Schuessler

Continue implementing the progress tracking.

1 parent 4985f30a
......@@ -62,7 +62,19 @@ public class NGINXUploadProcessor extends HttpServlet {
throws ServletException, IOException {
if (request.getRequestURI().contains("progress")) {
PrintWriter out = new PrintWriter(response.getWriter());
out.println("({ \"state\" : \"uploading\", \"received\" : 21216, \"size\" : 379686 });");
String xProgressId = request.getHeader("X-Progress-ID");
System.err.println("PROGRESS: " + xProgressId);
if (xProgressId != null && progress.get(xProgressId) != null) {
ProgressRecord record = progress.get(xProgressId);
String status = "done";
if (record.bytesRead < record.contentLength) {
status = "uploading";
}
out.println("({ \"state\" : \""+ status +"\", \"received\" : " +
record.bytesRead + ", \"size\" : " + record.contentLength + " });");
} else {
out.println("({ \"error\" : \"Invalid X-Progress-ID\" });");
}
out.close();
} else {
if (ServletFileUpload.isMultipartContent(request)) {
......@@ -84,6 +96,7 @@ public class NGINXUploadProcessor extends HttpServlet {
try {
Map<String, FileItem> itemMap = new HashMap<String, FileItem>();
String xProgressId = request.getParameter("X-Progress-ID");
System.err.println("STORE: " + xProgressId);
class UploadProgressListener implements ProgressListener {
String xProgressId;
......@@ -101,6 +114,8 @@ public class NGINXUploadProcessor extends HttpServlet {
};
ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress);
progress.put(xProgressId, new ProgressRecord(-1, 0, 1));
upload.setProgressListener(listener);
List<FileItem> items = (List<FileItem>)upload.parseRequest(request);
......