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

128
Views
blob to base64 conversion synchrorously in Javascript

I am calling a javascript function to initialize a variable value in Oracle Visual Builder (VBCS). The function takes the binary data as input and needs to return Base64 converted string synchronously so that the Base64 converted string is assigned to the VBCS variable.

The function does not return the Base64 converted string. How do I make it return the Base64 string to the calling function?

PageModule.prototype.convertbase64 = function (data) {

    const blob = new Blob([data], {

      type: "application/octet-stream"

    });

    function blobToBase64(blob) {
      return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(blob);
        reader.onloadend = () => resolve(reader.result.toString().substr(reader.result.toString().indexOf(',') + 1));
        reader.onerror = error => reject(error);
        console.log(new Date());
      });
    };

    const retstring = blobToBase64(blob).then(finalString => { return finalString });
 
    console.log('retstring value', retstring);

    return retstring;

};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is in this line

const retstring = blobToBase64(blob).then(finalString => { return finalString });

You should wait for the result of blobToBase64 and make function convertbase64 async.

const retstring = await blobToBase64(blob);

Here is full example.

PageModule.prototype.convertbase64 = async function (data) {

const blob = new Blob([data], {
  type: "application/octet-stream"
});

function blobToBase64(blob) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = () => resolve(reader.result.toString().substr(reader.result.toString().indexOf(',') + 1));
    reader.onerror = error => reject(error);
    console.log(new Date());
  });
};

const retstring = await blobToBase64(blob);

console.log('retstring value', retstring);

return retstring;
};

about 4 years ago · Juan Pablo Isaza Report
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!