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.