My goal is to save each downloadURL from multiple promises (files being uploaded) in an array while iterating through them. However, what's happening is that I only get the first output for every item, regardless of how many items I upload. It keeps giving me the first downloadURL from the first promise.
If there was a way to label each promise so they don't overlap and give me the same value for each file, or perhaps pause each one and wait for the first one to finish before starting the next one. The first solution seems more appealing to me, but I'm still unsure how to implement it.
pushUpload(upload: Upload) {
let storageRef = firebase.storage().ref();
this.uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`).put(upload.file);
this.uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
// upload in progress
upload.progress = Math.ceil((snapshot.bytesTransferred / snapshot.totalBytes) * 100)
},
(error) => {
// upload failed
console.log(error)
},
() => {
// upload success
this.uploadTask.snapshot.ref.getDownloadURL().then((url)=>{
this.uploadInfo.push(url)
})
})
};
uploadMultiple() {
let files = this.selectedFiles
let filesIndex = _.range(files.length)
_.each(filesIndex, (idx)=>{
this.currentUpload = new Upload(files[idx]);
this.service.pushUpload(this.currentUpload);
})
}