I'm trying to send an image (cut in several pieces) by mqtt, receive it in my application and print it.
This is the code of receiving
function onMessageArrived(r_message) {
nbr=nbr+1; // count number of message
console.log("message here "+nbr);
//console.log(r_message.payloadBytes);
if (r_message.payloadBytes != 'end'){
console.log("i'm in the if");
b64c = (r_message.payloadBytes); // the b64c is decalred as var b64c = new String();
console.log(b64c);
myjpeg = myjpeg + _base64ToArrayBuffer(b64c); // add the part of image to myjpeg decalred as let myjpeg
}
else{
console.log("i'm in the else ");
console.log(r_message.payloadBytes);
myjpeg = arrayBufferToBase64(myjpeg); // transform an uint8array to base 64
document.getElementById('img_import').src = "data:image/jpg;base64," + myjpeg; // print image
}
and the funcction bas64toarray code :
function _base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
The image part is sent as base64 but I receive it in form of Uint8array, I'm trying to decode base64 by using the _base64ToArray() but it doesn't work, maybe because b64c is not a string and I have this error:

so, does someone know how I can decode b64c?