have built a websocket server in C and can send/receive text ok, have changed the opcode to binary (130) and am trying to send a small image (574 bytes). client side binary type is set to "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 from the file reader is; (data:;base64,/9j/4AAAAAA etc... etc... lots of A's).
the size of evt.data matches the file sent from the server (574 bytes) but reader.result doesn't appear to have any content (hence the A's). does anyone know what i am doing wrong?