[英]Glassfish 3.1.2.2 file upload
I'm having an issue when I try to upload a file in my application. 尝试在应用程序中上传文件时遇到问题。
The application server is Glassfish 3.1.2.2. 应用程序服务器是Glassfish 3.1.2.2。
Server side I'm using Spring MVC. 服务器端我正在使用Spring MVC。 So I declared in
beans.xml
: 所以我在
beans.xml
声明了:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
In the controller, I have : 在控制器中,我有:
@RequestMapping(value = "/processUpload", method = RequestMethod.POST)
@ResponseBody
public Object processUpload(MultipartHttpServletRequest request) {
... do something with request.getFiles(...); ...
}
On the client side, I'm using XMLHttpRequest
: 在客户端,我正在使用
XMLHttpRequest
:
xhr.open('POST', url, true);
var formData = new FormData();
formData.append('something', ...);
formData.append('file', file);
It's working with small files but with larges files, it keeps giving me this exception message : 它适用于小文件,但适用于大文件,它不断给我以下异常消息:
Stream ended unexpectedly
What I tried : 我试过了
max-post-size-bytes="0"
or max-post-size-bytes="1073741824"
(= 1go / test-file = 300mo) in domains.xml max-post-size-bytes="0"
或max-post-size-bytes="1073741824"
(= 1go /测试文件= 300mo) <bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
instead of commons-fileupload + <multipart-config>
in web.xml <bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
代替web.xml中的commons-fileupload + <multipart-config>
Thanks in advance, 提前致谢,
Smoky 烟
Finally, I found a solution : 最后,我找到了一个解决方案:
$.ajax({
type : 'POST',
url : '/processUpload',
data : formData,
dataType : 'text',
cache : false,
processData : false,
contentType : false,
xhr : function () {
... progress things ...
}
});
instead of using native XHR. 而不是使用本机XHR。
Working with : 使用:
org.springframework.web.multipart.commons.CommonsMultipartResolver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.