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

138
Views
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 answers
Answer question

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