javascript - blob filereader output appears to be empty (data:;base64,/9j/4AAAAAA...) -
have built websocket server in c , can send/receive text ok, have changed opcode binary (130) , trying send small image (574 bytes). client side binary type set "blob".
ws.binarytype = "blob";
javascript client;
function onmessage(evt) { if(evt.data instanceof blob){ console.log(evt.data.size);//574 bytes var reader = new filereader(); var img = document.queryselector("#img_test"); reader.onload = function(e) { img.src = reader.result; console.log(img.src); } reader.readasdataurl(evt.data); } else{ $("#txt_window").append(evt.data+'<br/>'); } }
the output file reader is; (data:;base64,/9j/4aaaaaa etc... etc... lots of a's).
the size of evt.data matches file sent server (574 bytes) reader.result doesn't appear have content (hence a's). know doing wrong?
Comments
Post a Comment