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

139
Visualizações
HTML 5 Filereader Not returning Base64 URL Onloadend

I am using the following script for reading image data as base64 url.

function getBase64(incomingfile) {

var reader = new FileReader;
reader.readAsDataURL(incomingfile);
reader.onloadend = ()=>{
    console.log(reader.result);
}

}

This is working fine and printing the result on console. But when I try to apply this below code

function getBase64(incomingfile) {

var reader = new FileReader;
reader.readAsDataURL(incomingfile);
reader.onloadend = ()=>{
    return reader.result;
}

}

I am not getting the result of this function after calling. What should I do to get return value of Filereader.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the file The FileReader methods work asynchronously but don't return a Promise so when attempting to retrieve the result immediately after calling a method will not work

try this

let logBase64 = "";
function getBase64(incomingfile) {
var reader = new FileReader();
reader.readAsDataURL(incomingfile);
return new Promise((resolve, reject) => {
reader.onloadend = () => {
  resolve(reader.result);
};
}).then((result) => {
logBase64 = result;
console.log(logBase64);
 });
 }
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