首页 > 解决方案 > Flutter 从 Firebase 存储中获取图像

问题描述

我找到了两种从 firebase 存储中获取图像的方法。

  1. 使用图像路径

将图像保存到存储时,将该图像路径存储到 firestore,并在获取图像时,使用来自 firestore 的图像路径并调用 FirebaseStorage 实例。

// In this case, get & post imagePath info String through firebase firestore
FirebaseStorage.instance.storage.ref().child('imagePath').getData()
  1. 使用图片网址

将图像保存到存储时,将该图像 url 存储到 firestore,并在获取图像时,使用 firestore 中的图像 url 作为网络图像(无需调用 FirebaseStorage 实例)。

// In this case, get & post imageUrl String through firebase firestore
Firestore.instance.collection('images').document('foo').get()

哪个是更好的方法?有性能差异吗?

标签: firebaseflutterdartgoogle-cloud-firestorefirebase-storage

解决方案


第一个片段通过该产品的 Firebase SDK 从 Cloud Storage 检索图像数据。Cloud Storage 是一种用于存储任何规模的博客/文件数据的解决方案。

第二个片段通过该产品的 Firebase SDK 从 Cloud Firestore 检索图像数据。Firestore 是一个 NoSQL 数据库,也适用于任何规模。

Cloud Storage 和 Cloud Firestore 是完全不同的产品,您必须自己选择要使用的产品。但一般指导是将非结构化数据存储到 Storage 中,并将更多结构化数据存储在 Firestore 中。


推荐阅读