Looking to upload an image file on the server using a servlet without utilizing HTML5. While browsing through stackoverflow, most answers I found were based on PHP. I attempted to read the image file at the client-side in JavaScript with FileReader.readAsDataURL() method and then send it to the server side, decrypting it by BASE64 to create a .jpg file. However, the resulting file was unreadable by the computer. Seeking assistance to resolve this issue. Any alternative methods for uploading are welcomed. Your response should focus on JAVA JAVA JAVA. AJAX implementation is also desired. Thank you.
I've successfully uploaded an image file using a servlet, which works fine. My attempt to upload an image using AJAX by calling the same servlet through an AJAX request is failing. Utilizing common-fileupload.jar and common-io.jar in my code snippet:
List items = new FileUpload(new DiskFileItemFactory())
.parseRequest(request);
This code doesn't work with AJAX as 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 appears as follows:
$.ajax({
type: "POST",
data: data,
cache: false,
url: "/uploadImage/upload",
contentType: false,
processData: false,
success: function() {
alert("Done..!!");
}
});