Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!