Home > Net >  How can i get Image URL from Firebase Storage to Firebase Database without uploading image from my a
How can i get Image URL from Firebase Storage to Firebase Database without uploading image from my a

Time:04-11

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.

CodePudding user response:

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();

CodePudding user response:

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.

  • Related