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

129
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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