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

171
Views
Upload image to array of base64

I want to make a upload image and preview, want to make all selected images to base64 and create an array from it, but after onload and array.push array return empty, any idea what's wrong? I'm using this code in reactjs but for demo to share you I managed to use jQuery

function handleImage(e) {
  let image = e.target.files;
  let result = [...image];
  let array = [];

  result && result.map(function(img, i) {
    let fileReader = new FileReader();
    fileReader.readAsDataURL(img);
    fileReader.onload = () => {
      array.push(fileReader.result);
    }
  })
  console.log(array) // return empty!
}

$('input[type="file"]').change(function(e) {
  handleImage(e)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" onChange="handleImage" />

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