I want to upload image file on server using servlet and i am not using HTML5. I have seen many questions of uploading image on stackoverflow but most of the answers are using PHP. I have tried it by reading image file at client side in java script using FileReader.readAsDataURL() method and then send this to server side and again make a .jpg file by decrypting it by BASE64. But the file made is not readable by computer. So please help me to solve this problem. Some other method for uploading are also appreciated. Please Answer me regarding JAVA JAVA JAVA. I also want to use AJAX :) Thank you.
I have done uploading Image file using servlet. It is working fine. I am trying to upload image using AJAX. I am calling same servlet through the AJAX request. But its not working. I am using common- fileupload.jar and common-io.jar for the same. Snippet looks like:
List items = new FileUpload(new DiskFileItemFactory())
.parseRequest(request);
This code not working with Ajax I am sending dataForm object as data.
data = new FormData();
jQuery.each($('#file')[0].files, function(i, file) {
data.append('file-'+i, file);
});
The ajax request looks like:
$.ajax({
type : "POST",
data: data,
cache: false,
url : "/uploadImage/upload",
contentType: false,
processData: false,
success : function() {
alert("Done..!!");
}
});