将文件上传到Spring时,net :: ERR_CONNECTION_ABORTED的可能原因是什么?

时间:2014-03-09 02:12:24

标签: java jquery spring

p我正在使用plupload(plupload.com)jQuery插件将AJAX图像文件发送到Java Spring服务器。我尝试过服务器端RESTful Controller Endpoint的不同实现。我已经附加了处理文件上传URL的特定方法。任何帮助将非常感激。谢谢。

@RequestMapping(value = "/pictureUpload", method = RequestMethod.POST )
public @ResponseBody 
String productPictureUploadPost(@RequestBody MultipartFile multipartFile) {
    HomeController.logger.info("In method productPictureUploadPost in SettingsPanelController. : Entering");
    String orgName = multipartFile.getOriginalFilename();

    String filePath = "/my_uploads/" + orgName;
    File dest = new File(filePath);
    try {
        multipartFile.transferTo(dest);
    } catch (IllegalStateException e) {
        e.printStackTrace();
        return "File uploaded failed:" + orgName;
    } catch (IOException e) {
        e.printStackTrace();
        return "File uploaded failed:" + orgName;
    }
    HomeController.logger.info("In method productPictureUploadPost in SettingsPanelController. Exiting : " + "File uploaded:" + orgName);   
    return "File uploaded:" + orgName;
}

我还附加了servlet .xml多部分解析器声明。

<bean class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/>

在客户端,我有一个调用的插件文件,如下所示。

$(document).ready(function() {
$("#uploader").plupload({
    // General settings
    runtimes: 'html5,flash,silverlight,html4',

    url: "/pictureUpload",

    // Maximum file size
    max_file_size: '1000mb',

    // User can upload no more then 20 files in one go (sets multiple_queues to false)
    max_file_count: 3,

    // Specify what files to browse for
    filters: [
        { title: "Image files", extensions: "jpg,jpeg,gif,png" }
    ],

    // Rename files by clicking on their titles
    rename: true,

    // Sort files
    sortable: true,

    // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
    dragdrop: true,

    // Views to activate
    views: {
        list: true,
        thumbs: true, // Show thumbs
        active: 'thumbs'
    },

    // Flash settings
    flash_swf_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/flash/Moxie.cdn.swf',

    // Silverlight settings
    silverlight_xap_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/silverlight/Moxie.cdn.xap'
});
});

1 个答案:

答案 0 :(得分:3)

在文件上传的上下文中,当HTTP服务器未完全读取客户端的HTTP请求正文并在中途上载时中止连接时,会发生net::ERR_CONNECTION_ABORTED。这通常发生在上传文件太大的情况下,服务器继续阅读请求并提前失败并不合理。

中止连接意味着客户端在收到响应之前不会浪费带宽上传文件,但会触发上述错误。

HTTP提供了早期连接终止,Expect: 100-continue请求标头和100 Continue响应状态,您可以在此处阅读:http://benramsey.com/blog/2008/04/http-status-100-continue/

不幸的是,大多数浏览器在文件上传期间都不发送它(Which browsers send the expect: 100-continue header?)。

但是,由于您在客户端使用Flash / Silverlight进行上传,我建议您尝试将上传小部件发送到服务器{/ 1}}。