Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
java-nginx-upload-processor
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4afee607
authored
2014-01-17 12:07:05 -0600
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Continue implementing the progress tracking.
1 parent
4985f30a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletions
src/com/brainfood/servlet/NGINXUploadProcessor.java
src/com/brainfood/servlet/NGINXUploadProcessor.java
View file @
4afee60
...
...
@@ -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
;
...
...
@@ -102,6 +115,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
);
for
(
FileItem
item
:
items
)
{
...
...
Please
register
or
sign in
to post a comment