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

173
Views
Issue in uploading multiple files and only 1 file to firebase storage

I can successfully upload multiple files to firebase storage the issue is when I try to upload only 1 file nothing happened.

When I have multiple files they are added to an array then I can upload it to firebase database but how to do it with only 1 file.

//choose files
  document.querySelector('#pictures').addEventListener('change', (e) => {

    const formData = extractFormData('#statusForm');
    while (fileCollection.length) {
      fileCollection.pop();
      console.log("test");

    }
    [].slice.call(formData.pictures).map(f => fileCollection.push(f));
    console.log(formData.pictures);

        
  });
    //choose files
  document.forms.statusForm.addEventListener('submit', (e) => {
    e.preventDefault();
    e.stopPropagation();

    const formData = extractFormData('#statusForm');
    const text = formData.status;
    formData.status = '';
    sendData(text, fileCollection)
    setTimeout(() => {
      while (fileCollection.length) {
        fileCollection.pop();
      }
    }, 100);
  }); 


var extractFormData = function (form) {
  const formData = new FormData(document.querySelector(form));
  values = {};


  for(var pair of formData.entries()) {
    if( values[pair[0]] ) {

      if(!(values[pair[0]] instanceof Array)) {
        values[pair[0]] = new Array(values[pair[0]]);

      }
      values[pair[0]].push(pair[1]);


    } else {

      values[pair[0]] = pair[1];

    }
  }

  console.log("values: " + values);

  return values;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is how it was fixed i changed the extractFormData function to

const extractFormData = function (form) {
  const formData = new FormData(document.querySelector(form));
  const values = {};
  for (let [key, value] of formData.entries()) {
    
    if (values[key]) {
      if ( ! (values[key] instanceof Array) ) {
        values[key] = new Array(values[key]);
      }
      values[key].push(value);

    } else {
      values[key] = value;
      if(typeof values[key] === 'undefined') {
        // does not exist
        console.log("doesnt exist")
    }
    else {
        // does exist
        values[key] = new Array(values[key]);
    }

    }
  }
  return values;
}
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!