title: downloadURL state change inside a loop
body: <p>I'm uploading a series o images to the firebase storage, and I need all the URL's of those images to link to in firebase Database. This is the code i'm using so far:</p>
  
  <pre><code>var imgArray = []
  
        for (var i=0; i &lt; document.getElementById("myFile").files.length; i++){
  
          var selectedFile = document.getElementById("myFile").files[i];
  
          var selectedStorageRef = firebase.storage().ref(this.estado + "/" + this.cidade + "/" + document.getElementById("nome-do-pico").value + "/" + selectedFile.name);
  
          var uploadTask = selectedStorageRef.put(selectedFile);
  
  
          uploadTask.on('state_changed', null, null, function (snapshot){
            var downloadURL = uploadTask.snapshot.downloadURL;
            imgArray.push(downloadURL);
            console.log(imgArray);
  
            });
  
        }
  </code></pre>
  
  <p>The idea is to get them all in an array first, but I always gets just the last URL. If I try to upload 3 images for example sometimes I even get an array of [null, URL, URL] or [null, null, URL]. I rarely get 3 URL's, and in every case they are all the same.</p>