用如下代码,可以正常上传各类满足条件的文件;但文件大小超过限定值时,不能把拼接的字符串返回,控制台信息附后,如果关闭html5上传,则在报错信息中准确显示上传的原始文件名称,错误类型一样,表示准确捕获了异常。
@AdaptBy(type = UploadAdaptor.class, args ="ioc:upload")
@POST
@At
@Ok("raw")
@Fail("void")
public String upload(@Param("filedata") TempFile tmpFile,AdaptorErrorContext errCtx) {
String err = "";
String msg = "''";
if (errCtx != null && errCtx.getAdaptorErr() != null) {
err=errorMsg(errCtx.getAdaptorErr());
return "{'err':'" + jsonString(err) + "','msg':" + msg + "}";
}
2017-03-26 13:14:23,629 [INFO][org.nutz.mvc.adaptor.AbstractAdaptor] - Adapter Error catched , but I found AdaptorErrorContext param, so, set it to args, and continue
org.nutz.mvc.upload.UploadOutOfSizeException: File 'nutz.jpg' out of size!
at org.nutz.mvc.upload.Html5Uploading.parse(Html5Uploading.java:43)
at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:193)
at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:62)
at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:226)
at org.nutz.mvc.upload.UploadAdaptor.adapt(UploadAdaptor.java:117)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)