Getting download URLs from FirebaseStorage

Issue

Is there a way to get all the URLs of the files located in a specific firebase storage library?
Currently using the following method:

List<String> URLs = [];
  final ListResult _files = await _fireStorage.ref('groups/').list();


  for (var element in _files.items) {
    String addable = await element.getDownloadURL();
    URLs.add(addable);
  }

MY problem is that I have lots of files located in the groups folder and this async call takes like a ton of time to fetch for all individual elements. Is there any API call to get the links in bulk? Or should I just store the links in a firebase document and fetch them from there?

Thanks in advance!

Solution

In order to successfully return the downloadURL the client has to ping the storage bucket. Firebase then has to check the security rules to ensure that the operation is allowed, then verify that the object exists, and then return it’s download URL to you. Unfortunately there is currently no way of doing this process in bulk.

It’s quite common to store the downloadURL in a Firestore document so you can avoid the additional overhead and retrieve the downloadURL directly. But remember, downloadURLs are public and do not adhere to security rules. So make sure the document you’re storing them in has proper rules placed on it.

Remember to perform a clean up operation and remove the reference in Firestore if you every delete the file.

Answered By – Hydra

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *