其他数据不会被推入数据库,只有图像

Other data does not get pushed into database, only image

下面,我有一个函数试图将目标添加到我的实时数据库中将图像上传到 Firebase 存储之后。

上传图片并return URL:

  Future uploadDestinationImage(String name) async {
    final imageref = FirebaseStorage.instance
        .ref()
        .child('destinations')
        .child(name + '.jpg');

    imageref.putFile(selectedImage!);
    return await imageref.getDownloadURL();
  }

正在向数据库中添加数据:

  void addDestination(String name, String details, var category) async {
    if (category == 'Destination') {
      uploadDestinationImage(name).then((value) {
        String desturl = value;
        String key = destdatabaseref.child('Destinations').push().key;
        destdatabaseref.child('Destinations').child(key).set({
          'id': key,
          'name': name,
          'description': details,
          'category': category,
          'photoURL': desturl
        });
      });
    }
  }

但是,该代码仅将图像上传到 Firebase 存储,不会将数据推送到我的实时数据库。某处有错误吗?还有其他方法可以让我return下载URL图像并将其存储到数据库中吗?

putFile 调用是异步的,因此您也需要等待它:

await imageref.putFile(selectedImage!);
return await imageref.getDownloadURL();