Continue implementing the progress tracking.
Showing
1 changed file
with
16 additions
and
1 deletions
... | @@ -62,7 +62,19 @@ public class NGINXUploadProcessor extends HttpServlet { | ... | @@ -62,7 +62,19 @@ public class NGINXUploadProcessor extends HttpServlet { |
62 | throws ServletException, IOException { | 62 | throws ServletException, IOException { |
63 | if (request.getRequestURI().contains("progress")) { | 63 | if (request.getRequestURI().contains("progress")) { |
64 | PrintWriter out = new PrintWriter(response.getWriter()); | 64 | PrintWriter out = new PrintWriter(response.getWriter()); |
65 | out.println("({ \"state\" : \"uploading\", \"received\" : 21216, \"size\" : 379686 });"); | 65 | String xProgressId = request.getHeader("X-Progress-ID"); |
66 | System.err.println("PROGRESS: " + xProgressId); | ||
67 | if (xProgressId != null && progress.get(xProgressId) != null) { | ||
68 | ProgressRecord record = progress.get(xProgressId); | ||
69 | String status = "done"; | ||
70 | if (record.bytesRead < record.contentLength) { | ||
71 | status = "uploading"; | ||
72 | } | ||
73 | out.println("({ \"state\" : \""+ status +"\", \"received\" : " + | ||
74 | record.bytesRead + ", \"size\" : " + record.contentLength + " });"); | ||
75 | } else { | ||
76 | out.println("({ \"error\" : \"Invalid X-Progress-ID\" });"); | ||
77 | } | ||
66 | out.close(); | 78 | out.close(); |
67 | } else { | 79 | } else { |
68 | if (ServletFileUpload.isMultipartContent(request)) { | 80 | if (ServletFileUpload.isMultipartContent(request)) { |
... | @@ -84,6 +96,7 @@ public class NGINXUploadProcessor extends HttpServlet { | ... | @@ -84,6 +96,7 @@ public class NGINXUploadProcessor extends HttpServlet { |
84 | try { | 96 | try { |
85 | Map<String, FileItem> itemMap = new HashMap<String, FileItem>(); | 97 | Map<String, FileItem> itemMap = new HashMap<String, FileItem>(); |
86 | String xProgressId = request.getParameter("X-Progress-ID"); | 98 | String xProgressId = request.getParameter("X-Progress-ID"); |
99 | System.err.println("STORE: " + xProgressId); | ||
87 | 100 | ||
88 | class UploadProgressListener implements ProgressListener { | 101 | class UploadProgressListener implements ProgressListener { |
89 | String xProgressId; | 102 | String xProgressId; |
... | @@ -102,6 +115,8 @@ public class NGINXUploadProcessor extends HttpServlet { | ... | @@ -102,6 +115,8 @@ public class NGINXUploadProcessor extends HttpServlet { |
102 | 115 | ||
103 | ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress); | 116 | ProgressListener listener = (ProgressListener) new UploadProgressListener(xProgressId, this.progress); |
104 | 117 | ||
118 | progress.put(xProgressId, new ProgressRecord(-1, 0, 1)); | ||
119 | |||
105 | upload.setProgressListener(listener); | 120 | upload.setProgressListener(listener); |
106 | List<FileItem> items = (List<FileItem>)upload.parseRequest(request); | 121 | List<FileItem> items = (List<FileItem>)upload.parseRequest(request); |
107 | for (FileItem item : items) { | 122 | for (FileItem item : items) { | ... | ... |
-
Please register or sign in to post a comment