Added message field
This commit is contained in:
parent
4c7d85a806
commit
e508fbe783
3 changed files with 37 additions and 15 deletions
|
|
@ -135,15 +135,7 @@ public abstract class AjaxFileUpload extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
JSONNode node = new JSONNode( JSONType.Map );
|
||||
node.add("id", listener.getID());
|
||||
node.add("filename", listener.getFilename());
|
||||
node.add("percent", listener.getPercentComplete());
|
||||
node.add("uploaded", StringUtil.formatBytesToString( listener.getBytesRead() ));
|
||||
node.add("total", StringUtil.formatBytesToString( listener.getContentLength() ));
|
||||
node.add("speed", StringUtil.formatBytesToString( listener.getSpeed() )+"/s");
|
||||
node.add("status", listener.getStatus().toString());
|
||||
root.add(node);
|
||||
root.add( listener.getJSON() );
|
||||
}
|
||||
|
||||
// Write to the user
|
||||
|
|
@ -214,6 +206,8 @@ public abstract class AjaxFileUpload extends HttpServlet {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
listener.setStatus(Status.Error);
|
||||
listener.setFileName("");
|
||||
listener.setMessage( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,19 +67,21 @@ function updateUploadStatus(){
|
|||
$("#UploadQueue").append("<li id='"+item.id+"'>{PROGHTML}</li>");
|
||||
}
|
||||
// Update data
|
||||
if(jQuery("#UploadQueue #"+item.id+" .status").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .status").html( item.status );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .message").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .message").html( item.message );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .filename").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .filename").html( item.filename );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .progress").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .progress").animate({width: item.percent+"%"}, 'slow');
|
||||
//jQuery("#UploadQueue #"+item.id+" #progress").css("width", item.percent+"%");
|
||||
|
||||
if(jQuery("#UploadQueue #"+item.id+" .total").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .total").html( item.total );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .uploaded").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .uploaded").html( item.uploaded );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .speed").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .speed").html( item.speed );
|
||||
if(jQuery("#UploadQueue #"+item.id+" .status").size() > 0)
|
||||
jQuery("#UploadQueue #"+item.id+" .status").html( item.status );
|
||||
|
||||
// remove li when done
|
||||
if( item.status == "Done" ){
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package zutil.jee.upload;
|
|||
|
||||
import org.apache.commons.fileupload.ProgressListener;
|
||||
|
||||
import zutil.StringUtil;
|
||||
import zutil.parser.json.JSONNode;
|
||||
import zutil.parser.json.JSONNode.JSONType;
|
||||
|
||||
|
||||
/**
|
||||
* This is a File Upload Listener that is used by Apache
|
||||
|
|
@ -19,11 +23,12 @@ public class FileUploadListener implements ProgressListener{
|
|||
}
|
||||
|
||||
private String id;
|
||||
private volatile Status status;
|
||||
private volatile String filename;
|
||||
private volatile String message;
|
||||
private volatile long bytes = 0l;
|
||||
private volatile long length = 0l;
|
||||
private volatile int item = 0;
|
||||
private volatile Status status;
|
||||
private volatile long time;
|
||||
|
||||
// Speed
|
||||
|
|
@ -56,12 +61,14 @@ public class FileUploadListener implements ProgressListener{
|
|||
|
||||
protected void setFileName(String filename){
|
||||
this.filename = filename;
|
||||
item++;
|
||||
}
|
||||
protected void setStatus(Status status){
|
||||
this.status = status;
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
protected void setMessage(String msg){
|
||||
this.message = msg;
|
||||
}
|
||||
|
||||
|
||||
public String getID(){
|
||||
|
|
@ -92,6 +99,10 @@ public class FileUploadListener implements ProgressListener{
|
|||
return time;
|
||||
}
|
||||
|
||||
protected String getMessage(){
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bytes per second
|
||||
*/
|
||||
|
|
@ -107,4 +118,19 @@ public class FileUploadListener implements ProgressListener{
|
|||
return 0;
|
||||
return (int)((100 * bytes) / length);
|
||||
}
|
||||
|
||||
public JSONNode getJSON() {
|
||||
JSONNode node = new JSONNode( JSONType.Map );
|
||||
node.add("id", id);
|
||||
|
||||
node.add("status", status.toString());
|
||||
node.add("message", message);
|
||||
node.add("filename", filename);
|
||||
node.add("percent", getPercentComplete());
|
||||
|
||||
node.add("uploaded", StringUtil.formatBytesToString( bytes ));
|
||||
node.add("total", StringUtil.formatBytesToString( length ));
|
||||
node.add("speed", StringUtil.formatBytesToString( speed )+"/s");
|
||||
return node;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue