Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda