关于apache-commons-fileupload 的一个异常

6 篇文章 0 订阅
1 篇文章 0 订阅
最近一个项目用到了apache-commons-fileupload组件 ,当客户端上传文件时,服务器却报了以下异常:
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (5309) exceeds the configured maximum (0)
	at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
	at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
	at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
	at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)
	at com.knowledge.service.impl.FileServiceImpl.uploadFile(FileServiceImpl.java:38)
	at com.knowledge.controller.FileOpServlet.doGet(FileOpServlet.java:31)

	at com.knowledge.controller.FileOpServlet.doPost(FileOpServlet.java:78)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)

	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)

	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:662)


代码如下:

DiskFileItemFactory factory = new DiskFileItemFactory();//文件项工厂
			ServletFileUpload sfu = new ServletFileUpload(factory);
			System.out.println(sfu.isMultipartContent(request));
			sfu.setFileSizeMax(2*1024*1024*1024);//单个文件大小限制2G
			sfu.setSizeMax(4*1024*1024*1024);//总文件大小限制4G

发现异常:
 the request was rejected because its size (5309) exceeds the configured maximum (0)  这句话说明我设置的文件限制大小为0,可我设置的是2*1024*1024*1024(2G)于是看了<pre name="code" class="java">sfu.setFileSizeMax(2*1024*1024*1024)这个方法,参数是一个long型的值,而我传入的是int型的值,强转变成0了, 所以改为<pre name="code" class="java">sfu.setFileSizeMax((long)2*1024*1024*1024) 解决问题!

 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值