Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring

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;
}

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'
});
});
like image 967
Artur G Vieira Avatar asked Mar 09 '14 02:03

Artur G Vieira


1 Answers

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 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/

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

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.

like image 113
mxxk Avatar answered Sep 24 '22 11:09

mxxk