多张图片上传并获取下载网址-Firebase

时间:2020-09-23 15:55:48

标签: firebase flutter dart google-cloud-firestore firebase-storage

我目前正在将多个图像上传到Firebase并将downloadUrl放入列表中。

  _imageList.forEach((element) async {
                      final StorageReference _ref = FirebaseStorage.instance
                          .ref()
                          .child("Users/ads/"); 
                      StorageUploadTask uploadTask =
                          _ref.putFile(element as i.File);

                      await uploadTask.onComplete;
                      print("Images uploaded");
                      String image_links = await _ref.getDownloadURL();
                      _imageUrls.add(image_links);// _imageUrls is a List
                    });

现在我想将_imageUrls分配到Firestore中。

 Map<String, dynamic> ads = {
                      'adTitle': widget.title,
                      'adPrice': widget.price,
                      'adCategory': widget.dropdownValue,
                      'adCondition': this.newCondtionVal,
                      'adDesc': widget.desc,
                      'user_id': uID,
                      'imageUrls_List': _imageUrls,//Images goes hear

           
                    };
                    crudObj
                        .addData(ads)
                        .then((value) => {
                              showInSnackBar("dataAdded"),
                            })
                        .catchError((e) {
                      print(e);
                    });

但是问题是:
首先将数据上传到firestore的工作(图像上传尚未完成),所以现在firestore中的imageUrls_List插槽为空。

是否可以将onComplete添加到getDownloadURL()函数中?

是否有其他选项可以在完成上传图像后运行 firestore上传

0 个答案:

没有答案