Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
JS Electron decode base 64 Uint8array

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:

error+ console.log of b64c

so, does someone know how I can decode b64c?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda