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 –