【问题标题】:Flutter: Store Image in Firestore DatabaseFlutter:将图像存储在 Firestore 数据库中
【发布时间】:2022-01-16 08:01:44
【问题描述】:

我想知道如何将图像存储在 Firestore 数据库中而不是存储中,以及如何检索图像。

【问题讨论】:

  • 记住 firestore 最大文档大小约为 1MB。
  • 嗨,为什么要将图像存储在 Firestore 数据库中?我认为将图像存储在数据库中不是一个好习惯,这不是一种经济有效的方式,而且 Firestore 中文档的大小限制为 1MB。阅读storing images in Firestore,如果有帮助请告诉我?

标签: firebase flutter google-cloud-firestore


【解决方案1】:

Firestore 仅存储 JSON 数据。您必须将图像托管在某个地方才能显示它。您应该使用firebase_storage 来存储该图像。

Future<String> getImageUrl() async {
    Reference ref =
        FirebaseStorage.instance.ref().child('pathToImage');
    String url = await ref.getDownloadURL();
    return url;
  }

【讨论】:

    猜你喜欢
    • 2020-04-16
    • 2021-07-23
    • 2021-10-14
    • 2012-10-17
    • 2017-07-24
    • 2011-04-15
    相关资源
    最近更新 更多