Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all files inside a Firebase Storage directory using Flutter

I have an App that display nightclub description and image. Each club have about 4 related image. In Firebase Storage i have created directory for each club and then stored their image inside.

so what i want to do is getting all the image from a club directory so i can display all the image in my app

i think a way of achieving this would be to get the DownloadUrl of each image.

i've tried this :

final StorageReference firebaseStorageRef = FirebaseStorage.instance.ref() .child('profilePics/$clubID/SomeImage.jpg').getDownloadURL();

but since i don't know in advance the name of the image stored i can't use this

so any way of doing this ?

like image 436
Jérémy Avatar asked Oct 26 '25 00:10

Jérémy


1 Answers

Future<void> listExample() async {
    firebase_storage.ListResult result =
        await firebase_storage.FirebaseStorage.instance.ref().listAll();

    result.items.forEach((firebase_storage.Reference ref) {
        print('Found file: $ref');
    });

    result.prefixes.forEach((firebase_storage.Reference ref) {
        print('Found directory: $ref');
    });
}

this code worked for me i got it from flutter fire website

here is the link to the docs https://firebase.flutter.dev/docs/storage/usage

like image 121
Ahmar Tauqir Avatar answered Oct 27 '25 18:10

Ahmar Tauqir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!