How to upload multiple images to Firebase Storage and return multiple downloadURLs

前端 未结 1 725
刺人心
刺人心 2021-01-17 02:00

We are working on a simple e-commerce app where we need to upload multiple product images. Using Vuejs and Vue-Croppa, we need to upload the images to firebase storage, retr

1条回答
  •  再見小時候
    2021-01-17 02:32

    For your second issue.....

    Set up a promise for each image you want to upload.

    So in your loop call a method "similar" to the below (I've just grabbed this out of one of my projects):

    uploadImageAsPromise (imageFile) {
        const self = this;
    
            return new Promise(function (resolve, reject) {
                var storageRef = firebase.storage().ref("/imagestestnew/"+imageFile.name);
    
                //Upload file
                var task = storageRef.put(imageFile);
    
    
                //Update progress bar
                task.on('state_changed',
                    function progress(snapshot){
    
                        var percentage = snapshot.bytesTransferred / snapshot.totalBytes * 100;
                        console.log("percentage" + percentage)
                        self.progressUpload = percentage;
                    },
                    function error(err){
                        console.log("error")
                    },
                    function complete(){
                        console.log("done")
                        var downloadURL = task.snapshot.downloadURL;
                    }
                );
            });
    }
    

    0 讨论(0)
提交回复
热议问题