I’m using spring-mvc and jquery uploadify to upload an image, my uploadify script saves the image on my server, my image is getting saved but uploadify is throwing HTTP error and onComplete is not getting fired. I made sure that my script is returning something. here is my code.
$(document).ready(function() {
$('#upload').click(function() {
$('#uploadify').uploadifyUpload();
return false;
});
$('#uploadify').uploadify({
'uploader': 'js/uploadify/uploadify.swf',
'script': 'uploadcreate.htm;jsessionid=${sessionId}',
'multi': false,
'auto' : true,
'fileDesc': 'JPG Image Files (*.jpg),JPG Image Files (*.JPG),JPG Image Files (*.JPEG)',
'fileExt' : '*.jpg;*.jpeg;*.JPEG;',
'cancelImg': 'js/uploadify/cancel.png',
onComplete: function (event, queueID, fileObj, response, data) {
alert("as");
//$("#showimage").html('<img src="' + response + '" height="500" width="500" /><br />http://localhost:8080' + fileObj.filePath);
}
});
});
and my controller code is:
@RequestMapping(value="/uploadcreate.htm", method = RequestMethod.POST)
public JSONObject uploadcreate(UploadProperties uploadbean, BindingResult result, HttpServletRequest request, Model model) {
System.out.println("started uploading");
if (result.hasErrors()) {
for (ObjectError error : result.getAllErrors()) {
System.err.println("Error in uploading: " + error.getCode()
+ " - " + error.getDefaultMessage());
}
return null;
}
String relativeWebPath = "/WEB-INF/uploads";
String absoluteFilePath = request.getServletContext().getRealPath(relativeWebPath);
String username = request.getUserPrincipal().getName();
JSONObject filepath = uploadFacade.upload(uploadbean, username, absoluteFilePath);
model.addAttribute("filePath", filepath);
return filepath;
}
The main problem with above implementation was with sessionId, my spring security somehow was creating different session Id and that is why my request was not getting authenticated. I removed the security from my spring security configuration file like this
I faced some other issues after that but I bypassed this said problem by handling the session properly.