user12208004
user12208004

Reputation: 1998

Flutter Fetch Images from Firebase Storage

I found the two ways to fetch images from firebase storage.

  1. Using imagePath

When saving an image to storage, store that image path to firestore, and when fetching the image, use that image path from firestore and call FirebaseStorage instance.

// In this case, get & post imagePath info String through firebase firestore
FirebaseStorage.instance.storage.ref().child('imagePath').getData()
  1. Using image url

When saving an image to storage, store that image url to firestore, and when fetching the image, use that image url from firestore as network image (no need to call FirebaseStorage instance).

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

Which one would be the better way? Is there any performance difference?

Upvotes: 0

Views: 1074

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600100

The first fragment retrieves image data from Cloud Storage through the Firebase SDK for that product. Cloud Storage is a solution for storing blog/file data, at any scale.

The second fragment retrieves image data from Cloud Firestore through the Firebase SDK for that product. Firestore is a NoSQL database, and also works at any scale.

Cloud Storage and Cloud Firestore are completely different products, and you'll have to choose yourself which one to use. But the general guidance would be to store unstructured data into Storage, and more structured data in Firestore.

Upvotes: 1

Related Questions