2
spring-mvc 및 jquery uploadify를 사용하여 이미지를 업로드하고 업로드 스크립트가 내 서버에 이미지를 저장하고 이미지가 저장되지만 업로드 오류로 인해 HTTP 오류가 발생하고 onComplete가 표시되지 않습니다. 해고 됐어. 내 대본에서 뭔가를 돌려주고 있는지 확인했습니다. 여기 내 코드가있다. Uploadify onComplete가 호출되지 않습니다.
$(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);
}
});
});
내 컨트롤러 코드는 다음과 같습니다 위의 구현
@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;
}