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'
});
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With