简体   繁体   English

Glassfish 3.1.2.2文件上传

[英]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 domains.xml中的max-post-size-bytes="0"max-post-size-bytes="1073741824" (= 1go /测试文件= 300mo)
  • change web-core.jar with the one provided in https://java.net/jira/browse/GLASSFISH-18444 使用https://java.net/jira/browse/GLASSFISH-18444中提供的内容更改web-core.jar
  • change commons-io, commons-fileupload with the ones in glassfish/libs 用glassfish / lib中的文件更改commons-io,commons-fileupload
  • change web-core independantly / change commons libs independantly 独立更改网络核心/独立更改公用库
  • use <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
  • last commons-io / commons-fileupload librairies 上一个commons-io / commons-fileupload库
  • default glassfish web-core.jar 默认的glassfish web-core.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM