0
我想在sedig到服务器之前将图像转换为base64。如何在jQuery中做到这一点?在jquery中将图像转换为base64用于文件jpg
HTML:
<input id="imgFld" type="file" accept="image/*;capture=camera" style="display:block;"/>
<input type="submit" id="submitImage" name=submit/>
JS:
$(文件)。就绪(函数(){
alert("hello");
$("#submitImage").on('click',function(e){
e.preventDefault();
var ext = $('#imgFld').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
alert('Invalid extension!, Please choose the right extension - gif, jpg/jpeg or png');
}
else{
//covert to base64 and send ajax post
}
});
经典问题 - http://stackoverflow.com/的可能的复制问题/ 6150289 /如何对转换图像 - 到 - 基于64位字符串使用的JavaScript –