项目有有时候会有大文件上传,四五百M,有时候上传接收不到流
可是上传小文件就没有问题
就是用得Formfile
好奇怪
项目架子struts1+spring2.5+hibernate
上传文件时,会处理request中的内容。
最终才会调用commonupload组件上传
struts中类
org.apache.struts.upload.CommonsMultipartRequestHandler
做了这一操作
[code="java"] public void handleRequest(HttpServletRequest request)
throws ServletException {
// Get the app config for the current request.
ModuleConfig ac =
(ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
// Create and configure a DIskFileUpload instance.
DiskFileUpload upload = new DiskFileUpload();
// The following line is to support an "EncodingFilter"
// see http://issues.apache.org/bugzilla/show_bug.cgi?id=23255
upload.setHeaderEncoding(request.getCharacterEncoding());
// Set the maximum size before a FileUploadException will be thrown.
upload.setSizeMax(getSizeMax(ac));
// Set the maximum size that will be stored in memory.
upload.setSizeThreshold((int) getSizeThreshold(ac));
// Set the the location for saving data on disk.
upload.setRepositoryPath(getRepositoryPath(ac));
// Create the hash tables to be populated.
elementsText = new Hashtable();
elementsFile = new Hashtable();
elementsAll = new Hashtable();
// Parse the request into file items.
List items = null;
try {
items = upload.parseRequest(request);
} catch (DiskFileUpload.SizeLimitExceededException e) {
// Special handling for uploads that are too big.
request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
Boolean.TRUE);
return;
} catch (FileUploadException e) {
log.error("Failed to parse multipart request", e);
throw new ServletException(e);
}
// Partition the items into form fields and files.
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
addTextParameter(request, item);
} else {
addFileParameter(item);
}
}
}[/code]
而在代码
[code="java"]upload.setSizeMax(getSizeMax(ac))[/code]
中会设置上传的最大值限制,如果超过最大值,会在request当值一个标识过大的参数值为true
[code="java"]request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
Boolean.TRUE);[/code]
然后调用者会根据request的MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED是不是true来决定来不要放null值
当然这个最大值也是可以配置文件中配置的。注意最后在配置的数字后带上M,K子符号
[code="java"] [/code]
Struts的默认的最大上传文件有限制。
enctype="multipart/form-data"去掉
可以在 struts.xml中配置大小(以kb计)
[code="xml"]
[/code]
但是,大文件还是建议用FTP。
http://blog.csdn.net/foamflower/archive/2008/08/29/2850067.aspx
试试看这个解决方法。
参考解决方案
http://blog.csdn.net/iwindyforest/archive/2008/01/25/2065791.aspx