且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将多个图像上传到Firebase存储并返回多个下载URL

更新时间:2022-05-16 22:34:15

第二个问题.....

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;
                }
            );
        });
}