NutzCN Logo
问答 再现上传文件过大问题
发布于 849天前 作者 lrw124 778 次浏览 复制 上一个帖子 下一个帖子
标签:

用如下代码,可以正常上传各类满足条件的文件;但文件大小超过限定值时,不能把拼接的字符串返回,控制台信息附后,如果关闭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)
9 回复

我觉得原因是html5上传的时候,当服务器拒绝继续读取数据(nutz会抛出异常,不再读取剩余数据),浏览器端的js就抛异常了,然后没再读取服务器的响应,直接走error事件

这种情况,既然js端能走html5,那就肯定能限制文件大小了,在浏览器端限制一下吧

用户使用的浏览器不确定能走H5,所以主要依赖服务器端。当限制H5上传时,报错如下,浏览器端该如何获知服务器拒绝继续读取数据?

2017-03-26 13:37:46,654 [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 'Wildlife.wmv' out of size!
	at org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:171)
	at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:186)
	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)

用的啥上传插件,浏览器端

或者换个方式,在入口方法内判断文件大小

取消UploadAdaptor的使用?只要使用了UploadAdaptor,我在入口方法内再加文件大小判断也没用了。

uploadadpter默认没现在大小哦

默认没限制大小

大小限制是你自己设置的哦,去掉自定义,然后在入口方法内判断

搞定了,原来是自己设了一个套。谢谢wendal

添加回复
请先登陆
回到顶部