[SEAM] rich:fileUpload 不能立即提示文件大小超过最大值

yq81862 2012-10-16
限制文件大小为50M,选择一个1g的文件,allowFlash="true",进度条完成后,也就是文件
都上传完成后才会提示文件超过限制的50M,
<h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
通过这个输出可以看出是上传完成后。
.有没有解决这个问题的方法?
现在进行的尝试有:
web.xml
<filter>
<filter-name>applicationFilter</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>50000000</param-value>
</init-param>
</filter>
1,去掉
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>50000000</param-value>
</init-param>
把这个参数配置到spring配置文件,通过注入来设值,
然后再upload方法获取值大小,根据上传文件的大小和配置的大小比较,
上传文件的大小比配置的大小大直接返回。
结果是:根本就不调用upload方法。
2,查看源码:
org.ajax4jsf.Filter extends org.ajax4jsf.webapp.ConfigurableFilter
org.ajax4jsf.webapp.ConfigurableFilter extends  org.ajax4jsf.webapp.BaseFilter
class BaseFilter {
protected void processUploadsAndHandleRequest(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;

Map<String, String> queryParamMap = parseQueryString(httpRequest.getQueryString());
String uid = queryParamMap.get(FileUploadConstants.UPLOAD_FILES_ID);

if (uid != null) {

if (isMultipartRequest(httpRequest)) {
//这个地方对大小的验证,但是什么也没有做
MultipartRequest multipartRequest = new MultipartRequest(httpRequest, createTempFiles, maxRequestSize, uid);

Object oldAttributeValue = httpRequest.getAttribute(FileUploadConstants.FILE_UPLOAD_REQUEST_ATTRIBUTE_NAME);
httpRequest.setAttribute(FileUploadConstants.FILE_UPLOAD_REQUEST_ATTRIBUTE_NAME, multipartRequest);

try {
// 这个地方对大小的验证
if (isFileSizeRestricted(request, maxRequestSize)) {

boolean sendError = Boolean.parseBoolean(queryParamMap.get(SEND_HTTP_ERROR));
if (sendError) {
// 发生错位只是让response添加了一个值然后就返回了
response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
System.err.println("ERROR " + HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE + "request entity is larger than the server is willing or able to process.");
return;
} else {
printResponse(response, "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
}

} else if (!checkFileCount(httpRequest, queryParamMap.get("id"))) {
printResponse(response, "<html id=\"_richfaces_file_upload_forbidden\"></html>");
} else {

handleRequest(multipartRequest, multipartRequest.isFormUpload() ? response :
new HttpServletResponseWrapper((HttpServletResponse) response){
@Override
public void setContentType(String type) {
super.setContentType(BaseXMLFilter.TEXT_HTML + ";charset=UTF-8");
}
}, chain);

if (!multipartRequest.isDone()) {
printResponse(response, "<html id=\"_richfaces_file_upload_stopped\"></html>");
}
}

} finally {
httpRequest.setAttribute(FileUploadConstants.FILE_UPLOAD_REQUEST_ATTRIBUTE_NAME, oldAttributeValue);
multipartRequest.clearRequestData();
}
} else {
handleRequest(request, response, chain);
}
} else {
handleRequest(request, response, chain);
}
}
}

public MultipartRequest(HttpServletRequest request,
boolean createTempFiles, int maxRequestSize, String uid) {
super(request);
this.createTempFiles = createTempFiles;
this.uid = uid;

String contentLength = request.getHeader("Content-Length");
this.contentLength = Integer.parseInt(contentLength);
if (contentLength != null && maxRequestSize > 0
&& this.contentLength > maxRequestSize) {
// TODO : we should make decision if can generate exception in this
// place
// throw new FileUploadException(
// "Multipart request is larger than allowed size");
}
}
这个应该只是后台的返回,前台没有接收到,所以文件超长的时候不会调用upload方法,因为在filter里面已经返回了。
但是页面就继续上传,这个让人非常不理解。
请问这个是bug吗?  要怎么解决这个问题呢?
remoteJavaSky 2012-10-16
struts 也遇到类似问题。同问
Global site tag (gtag.js) - Google Analytics