将文件上传到Spring时,net :: ERR_CONNECTION_ABORTED的可能原因是什么? [英] What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring

查看:1445
本文介绍了将文件上传到Spring时,net :: ERR_CONNECTION_ABORTED的可能原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

pI am using a plupload (plupload.com) jQuery plugin to AJAX a image file to a Java Spring server. I have tried different implementations of the server side RESTful Controller Endpoint. I have attached the specific method which handles the file upload url. Any help will be very appreciated. Thank you.

@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多部分解析器声明。

Also I have attached the servlet .xml multipart resolver declaration.

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

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

On the client side I have the plugin file called as I have attached below.

$(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'
});
});


推荐答案

在文件上传的上下文中, net :: ERR_CONNECTION_ABORTED 当HTTP服务器未完全读取客户端的HTTP请求主体并中止上传连接时发生。这通常发生在上传文件太大的情况下,服务器继续读取请求并提前失败是没有意义的。

In the context of a file upload, net::ERR_CONNECTION_ABORTED happens when the HTTP server does not fully read the client's HTTP request body and aborts the connection mid-upload. This usually happens when the file being uploaded is too large, where it doesn't make sense for the server to continue reading request and fail early instead.

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

Aborting the connection means the client does not waste bandwidth uploading the file before receiving the response, but does trigger the aforementioned error.

HTTP有早期连接终止的条款,期望:100-continue 请求标头和 100继续响应状态,您可以在此处阅读: http://benramsey.com/blog/2008/04/http-status-100-continue/

HTTP has a provision for an early connection termination, the Expect: 100-continue request header and 100 Continue response status, which you can read about here: http://benramsey.com/blog/2008/04/http-status-100-continue/

不幸的是,大多数浏览器在文件上传过程中都不发送它(哪些浏览器发送期望:100-continue标题?

Unfortunately, most browsers do not send it during a file upload (Which browsers send the expect: 100-continue header?).

但是你正在使用Fla在客户端sh / Silverlight进行上传,我建议你考虑让你的上传小部件发送 Expect:100-continue 到服务器。

But since you're using Flash / Silverlight on the client side to do the upload, I'd recommend looking into making your upload widget send Expect: 100-continue to the server.

这篇关于将文件上传到Spring时,net :: ERR_CONNECTION_ABORTED的可能原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆