上传文件,超过大小限制后,返回了错误消息(record),但是页面接收不到错误消息。
报错信息:jquery-1.9.1.min.js:5 POST http://localhost:8888/bxacorp/upload/corp_onoff net::ERR_CONNECTION_RESET
后台代码
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
@At("/?/?")
@Filters
public Object upload(String fPath ,String cPath, @Param("file") TempFile[] tfs, HttpServletRequest req,
AdaptorErrorContext err) {
Record record = new Record();
if (err != null && err.getAdaptorErr() != null) {
record.set("name", "文件大小(<3M)或者文件格式不正确(doc|docx|txt|xls|xlsx|jpg|png|gif|jpeg|bmp)");
record.set("status", false);
} else {
//list = new ArrayList<Record>();
for (TempFile tf : tfs) {
record = Util.getFileJson(fPath,cPath, tf);
}
}
return record;
}
前端代码
upload.render({
elem: '#fg_file'
,url: '${base}/upload/corp_onoff'
,multiple: true
,accept:'file'
,before: function(obj){
layer.load(2); //上传loading
}
,done: function(res){
//接收文件
alert(res.name)
layer.closeAll('loading'); //关闭loading
if(res.status){
$('#fg_demo2').append('<a class="imgs" style="color:bule" id="img'+res.id+'" href="${base}/down/download?path='+ res.path +'&name='+res.name+'" alt="'+ res.name +'" class="layui-upload-img" style="font-size: 20px;">'+res.name+'</a>');
$('#fg_demo2').append('<i title="删除" class="layui-icon" id="del'+res.id+'" onclick="delIMG(\''+res.id+'\',this,\'img'+res.id+'\')" style="cursor:pointer;margin-right:5px;color:#FF5722;font-size: 25px;">ဇ</i><br/>');
$('#fg_hidimg').append('<input id="'+res.id+'" type="hidden" name ="hidimg" value=\''+JSON.stringify(res)+'\'></input>');
}else{
layer.msg(res.name,{icon:5});
}
}
,error: function(index, upload){
layer.closeAll('loading'); //关闭loading
}
});