JS Electron decode base 64 Uint8array

I’m trying to send an image (cut in several pieces) by mqtt, receive it in my application ans print it !

this is the code of receiving

function onMessageArrived(r_message) {
    nbr=nbr+1; // count number of message 
    console.log("message here "+nbr);
    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();
        myjpeg = myjpeg + _base64ToArrayBuffer(b64c); // add the part of image to myjpeg decalred as let myjpeg
        console.log("i'm in the else ");
        myjpeg = arrayBufferToBase64(myjpeg); // transform an uint8array to base 64
        document.getElementById('img_import').src = "data:image/jpg;base64," + myjpeg;  // print image

the image part is sent as base64 but i receive it in form of Uint8array, i’m trying to decode base 64 by using the _base64ToArray() but it’s don’t working, aybe because b64c is not a string and i have this error (look at the picture)

so, do someone know how i cant decode b64c ?
error+ console.log of b64c

Source: JavaSript – Stack Overflow

October 8, 2021
Category : News
Tags: base64 | electron | javascript | string | uint8array

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.