$("input:file").change(function(){ var thisObj = this; var reader = new FileReader(); reader.onload = function (e) { var data = e.target.result; //Load the image to get the real width and height of the image var image = new Image(); image.onload=function(){ var width = image.width; var height = image.height; $("img.showImageImg").attr("src",reader.result); }; image.src= data; }; reader.readAsDataURL(this.files[0]); });
reader.result gets the BASE64 section code
A file upload server can be implemented by transmitting BASE64
/** * * @param base64Str * @throws IOException */ public static void uploadBASE64(String base64Str) throws IOException{ BASE64Decoder d = new BASE64Decoder(); //data:image/gif;base64,R0lGODlhg..... //remove commas and strings before commas byte[] bs = d.decodeBuffer(base64Str); FileOutputStream os = new FileOutputStream("xxxx/x.gif"); os.write(bs); os.close(); }