I'm currently working on a WebSocket application that is displaying images send by a C++ server. I've seen a couple of topics around there but I can't seem to get rid of this error in Firefox:
Image corrupt or truncated: data:image/png;base64,[some data]
Here's the Javascript code I'm using to display my blob:
socket.onmessage = function(msg) {
var blob = msg.data;
var reader = new FileReader();
reader.onloadend = function() {
var string = reader.result;
var buffer = Base64.encode(string);
var data = "data:image/png;base64,"+buffer;
var image = document.getElementById('image');
image.src = data;
};
reader.readAsBinaryString(blob);
}
I'm using the image of a red dot that I found on this topic: https://mcmap.net/q/42153/-show-image-from-blob-in-javascript And the Base64 class is from here: https://mcmap.net/q/42154/-how-can-you-encode-a-string-to-base64-in-javascript
But the base64 outcome I get doesn't match and Firefox retrieves me an error of the image being corrupted.
I know this ain't much informations but I don't have a clue where to look :/ Any help is more than welcome!!
Base64.encode(string)
tobtoa(string)
. Most base64 libraries operate a bit differently thatbtoa
for high-value bytes; perhaps that's your issue? – Howling