I'm using Uploadify (and with Struts2 as back-end side) to upload file, whenever after I selected a file, a IO Error
or HTTP Error
would happen:
test.jpg (79.37KB) - HTTP Error
Here is JavaScript code:
$(select).uploadify({
'uploader' : BASE_PATH + 'js/uploadify-v2.1.4/uploadify.swf',
'script' : 'attachement/doUploadImage.action?jsessionid='+sessionId,
'scriptData': {'folder': 'customer'},
'auto' : true,
'buttonText': 'Select a image',
'displayData': 'percentage',
'fileDesc': 'Support Formats:jpg/gif/jpeg/png/bmp.',
'fileExt': '*.jpg;*.gif;*.jpeg;*.png;*.bmp',
'multi': false,
'cancelImg' : BASE_PATH + 'js/uploadify-v2.1.4/cancel.png',
'fileDataName': 'uploadFile',
'onComplete' : function(event, queueID, fileObj, response, data) {
// Do something
},
'onError': function(error) {
}
});
And following is the struts.xml configuation:
<package name="attachement" namespace="/attachement" extends="test-default">
<action name="do*" method="{1}" class="com.test.AttachmentAction">
</action>
</package>
And below is code in AttachmentAction:
private String folder;
private File uploadFile;
public void doUploadImage() {
Upload result = new Upload();
try {
log.info("Begin uploading the file " + uploadFile);
String filePath = IoUtil.saveAttachment(uploadFile, folder);
result.setSuccess(true);
result.setFilePath(filePath);
} catch (Exception e) {
e.printStackTrace();
result.setSuccess(false);
result.setMessage("Error: " + e.getMessage());
}
this.outJson(result);
}
And following is the information under firebug:
I don't know what makes this error happen? Can anybody gives me help. Thanks so much.
A few days later, this problem is solved. The root cause is that my project didn't include the Apache Jars upon which struts 2 upload functionality depends.
commons-fileupload.jar
commons-io.jar
Thanks!