class="js">$("input:file").change(function(){
var thisObj = this;
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
//加载图片获取图片真实宽度和高度
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]);
});
? ?monospace;">reader.result 得到BASE64节码
?可以通过传输BASE64实现文件上传服务器
?
/**
*
* @param base64Str
* @throws IOException
*/
public static void uploadBASE64(String base64Str) throws IOException{
BASE64Decoder d = new BASE64Decoder();
//data:image/gif;base64,R0lGODlhg.....
//去除逗号和逗号之前字符串
byte[] bs = d.decodeBuffer(base64Str);
FileOutputStream os = new FileOutputStream("xxxx/x.gif");
os.write(bs);
os.close();
}
?