Dhruval Golakiya
Dhruval Golakiya

Reputation: 13

How can i get Image URL from Firebase Storage to Firebase Database without uploading image from my app?

I upload one image from my computer to Firebase Storage and now I want that image to get in my Firebase database with his information and display it in my app. I can display information but cant display images. I google also but in every answer, they say first to upload the image to firebase storage from the app. then get his URL in the database and I don't want to upload from my app. So if someone know then help.

Upvotes: 0

Views: 1901

Answers (3)

Rishita Joshi
Rishita Joshi

Reputation: 415

Future<QuerySnapshot?> getDataFromFirebase() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    FirebaseFirestore.instance
        .collection('Images')
        .get()
        .then((QuerySnapshot? querySnapshot) {
      querySnapshot!.docs.forEach((doc) {
        List<dynamic> allImageData = doc["image_data"];
        storeImageList = allImageData.map((i) => i.toString()).toList();
      });
      prefs.setStringList("imageList", storeImageList);
    });
  }

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 600131

In addition to SARADAR21's excellent answer on how to get the data for a file at a known path, you can also list the files in Cloud Storage through the API, in case you don't know the path.

From that documentation:

final storageRef = FirebaseStorage.instance.ref();
final listResult = await storageRef.listAll();
for (var prefix in listResult.prefixes) {
  // The prefixes under storageRef.
  // You can call listAll() recursively on them.
}
for (var item in listResult.items) {
  // The items under storageRef.
}

You can then use the references you get this way, and call getDownloadUrl() to get a download URL for each of them.

Upvotes: 0

Anas Saradar
Anas Saradar

Reputation: 150

You Can Get the download link for your image Like this

     static final firebase_storage.FirebaseStorage storage =
  firebase_storage.FirebaseStorage.instance;
String url = await storage
    .ref('YourImagePath')
    .getDownloadURL();

Upvotes: 1

Related Questions