1

I'm currently trying to access the URL to a file from Firebase Storage without logging into the Firebase Console and grabbing the URL by hand. I'm developing an app that will be able to obtain that URL and store it as a string.

I've been hitting a lot of walls when doing this through Flutter and I've tried searching SO for a means of obtaining the URL programmatically.

So far, I've tried one method that looks like it works, but it isn't actually performing the task that I had intended for it to do.

void getDownloadUrl(String audioName) {
    FirebaseStorage firebaseStorage = FirebaseStorage.instance;
    StorageReference songRef = firebaseStorage.ref().child('$audioName');
    songRef.getMetadata().then(
        (_) => print('successfully accessed firebase storage child'),
        onError: (_) =>
            print("Wasn't able to access metadata from " + songRef.path));
    String audioString;
    songRef
        .getDownloadURL()
        .then((_) => audioString = songRef.getDownloadURL().toString());
    String audioPath;
    if (firebaseStorage != null) {
      audioPath = firebaseStorage.ref().child('$audioName').path;
    } else {
      print('songNameString is null. Check $audioPath');
    }
}

This is one method I've tried and it is still unsuccessful.

Can someone please explain the best practice for accessing Firebase Storage, search through the folder, get a hold of a file and access the required URL that can be stored for later use as that is the main goal I have for this section?

I have also opened permissions for read/write access to Firebase Storage.

Just to be clear - I'm not uploading a file through the app. So I don't think I'll be able to call the event that returns a URL upon upload.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
KoalaZub
  • 1,087
  • 8
  • 10

1 Answers1

1

Try This :

 printPath() async {
StorageReference ref =
FirebaseStorage.instance.ref().child('example/audio abc.mp3');
String url = (await ref.getDownloadURL()).toString();
print('Urlllllllllllllll $url');

}

Above code working fine .See below Screeenshot for refrence ;

Click Here to see the Image

  • I've attempted this method and it returns this: Instance of 'Future' So I'm confused as to whether or not it's working – KoalaZub Dec 02 '19 at 20:19
  • I've gone with grabbing the URL through storage by parsing that item's URL in console to the database and storing it there for use. I'm actually not sure if there's a better option through Flutter at the moment, as I've only seen methods to obtain a URL only after invoking an event call after [uploading an image/text file](https://stackoverflow.com/questions/52707610/flutter-get-firebasestorage-download-url-upload-status/52714376#52714376) – KoalaZub Dec 03 '19 at 13:47
  • Above code working fine , I was added a screenshot for reference check it now. – Shailendra mewada Dec 06 '19 at 18:19
  • It seems the function wasn't being invoked in the button that I implemented for some reason. Much appreciated on your assistance. – KoalaZub Dec 07 '19 at 13:14