Firebase getDownloadUrl cannot execute onSuccess or onFailure


tim_d:

I am trying to get URLaudio files in Cloud Storage. I can post it to storage, but this function just returns null. When debugging, it skips onSuccessboth and onFailure.

I know the filename variable is correct, but also tried hardcoding it without success. I mStorageRefpassed StorageReference. fileUrl is currently a global string.

mStorageRef = FirebaseStorage.getInstance().getReference();

String getFileUrl(String filename, StorageReference storageRef) {

        storageRef.child("music").child(filename).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                fileUrl = uri.toString();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                fileUrl = e.getMessage();
            }
        });

        return fileUrl;
    }

These files are located in a top-level folder called music.

Firebase Storage Structure

Alex Momo:

I can post it to storage, but this function just returns null.

You cannot now return content that has not been loaded. In other words, you can't simply create a fileUrlvariable as a global variable and use it outside a onSuccess()method , because it's always nulldue to the asynchronous behavior of that method. This means that when you try to use the result outside of that method, the data hasn't finished loading from the database and is therefore inaccessible.

A quick fix for this is to use the value fileUrlthat is from the database only inside the emit onSuccess()method, otherwise I suggest you look at the last part of my anwser post from this where I have explained how it can be used to do custom callbacks. You can also watch this video for a better understanding.

Also, make sure that the internet connection on the user's device is stable.

Related


Firebase getDownloadUrl cannot execute onSuccess or onFailure

tim_d: I am trying to get URLaudio files in Cloud Storage. I can post it to storage, but this function just returns null. When debugging, it skips onSuccessboth and onFailure. I know the filename variable is correct, but also tried hardcoding it without succes

Firebase getDownloadUrl cannot execute onSuccess or onFailure

tim_d: I am trying to get URLaudio files in Cloud Storage. I can post it to storage, but this function just returns null. When debugging, it skips onSuccessboth and onFailure. I know the filename variable is correct, but also tried hardcoding it without succes

Firebase getDownloadUrl cannot execute onSuccess or onFailure

tim_d: I am trying to get URLaudio files in Cloud Storage. I can post it to storage, but this function just returns null. When debugging, it skips onSuccessboth and onFailure. I know the filename variable is correct, but also tried hardcoding it without succes

Firebase Storage's getDownloadUrl() method cannot be resolved

Neeraj Sewani To upload images to Firebase Storage, attach to a StorageReference instance . When I override the method, the instance I am calling , but it gives me an erroraddOnSuccessListeneronSuccessgetDownloadUrl()taskSnapshot Cannot resolve method getDownl

Firebase Storage's getDownloadUrl() method cannot be resolved

Neeraj Sewani To upload images to Firebase Storage, attach to a StorageReference instance . When I override the method, the instance I am calling , but it gives me an erroraddOnSuccessListeneronSuccessgetDownloadUrl()taskSnapshot Cannot resolve method getDownl

Firebase Storage's getDownloadUrl() method cannot be resolved

Neeraj Sewani To upload images to Firebase Storage, attach to a StorageReference instance . When I override the method, the instance I am calling , but it gives me an erroraddOnSuccessListeneronSuccessgetDownloadUrl()taskSnapshot Cannot resolve method getDownl

Twitter Composer callback OnSuccess/OnFailure structure

Jon Anderson I'm trying to detect if the tweet was successful. How can I achieve this on Android using the Fabric (Twitter Composer) API? new TweetComposer.Builder(activity) .text("#hastag").show(); What I want to do: new Tweet

Twitter Composer callback OnSuccess/OnFailure structure

Jon Anderson I'm trying to detect if the tweet was successful. How can I achieve this on Android using the Fabric (Twitter Composer) API? new TweetComposer.Builder(activity) .text("#hastag").show(); What I want to do: new Tweet

Twitter Composer callback OnSuccess/OnFailure structure

Jon Anderson I'm trying to detect if the tweet was successful. How can I achieve this on Android using the Fabric (Twitter Composer) API? new TweetComposer.Builder(activity) .text("#hastag").show(); What I want to do: new Tweet

Twitter Composer callback OnSuccess/OnFailure structure

Jon Anderson I'm trying to detect if the tweet was successful. How can I achieve this on Android using the Fabric (Twitter Composer) API? new TweetComposer.Builder(activity) .text("#hastag").show(); What I want to do: new Tweet

Firebase getDownloadURL cannot set Img Src from storage

Ethan I am trying to replicate the results of this question here . I can call a getDownloadURL()valid database child, but the result it returns can't seem to be set to IMG's src. This is the code I'm currently using to try and get the download URL: var storage

Firebase getDownloadURL not working Android

Jetex Really need help, here are my Firebase Storage Security Rules service firebase.storage { match /b/shoppinglist-XXXX.appspot.com/o { match /{allPaths=**} { allow read, write; } } } Here is my java code to get the URL link storageRef = F

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Firebase getDownloadURL not working Android

Jetex Really need help, here are my Firebase Storage Security Rules service firebase.storage { match /b/shoppinglist-XXXX.appspot.com/o { match /{allPaths=**} { allow read, write; } } } Here is my java code to get the URL link storageRef = F

Firebase store getDownloadUrl is not a function

wabajoshi I'm developing a vue app with firebase, I've mentioned similar questions but didn't find any solution to my problem. What I want to do is store the download URL into my event database. my code: var stRef = st.ref(`event-photos/${eventId}`) // st is f

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Firebase getDownloadURL not working Android

Jetex Really need help, here are my Firebase Storage Security Rules service firebase.storage { match /b/shoppinglist-XXXX.appspot.com/o { match /{allPaths=**} { allow read, write; } } } Here is my java code to get the URL link storageRef = F

Firebase getDownloadURL not working Android

Jetex Really need help, here are my Firebase Storage Security Rules service firebase.storage { match /b/shoppinglist-XXXX.appspot.com/o { match /{allPaths=**} { allow read, write; } } } Here is my java code to get the URL link storageRef = F

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

World Time API call triggers onFailure instead of onSuccess

nzioker I'm trying to create a simple app that selects a time from an API, worldtimeapi and then displays it as soon as a button is clicked. However, when I click, the onFailure() method is fired. I don't understand why there seems to be a problem with onSucce

World Time API call triggers onFailure instead of onSuccess

nzioker I'm trying to create a simple app that selects a time from an API, worldtimeapi and then displays it as soon as a button is clicked. However, when I click, the onFailure() method is fired. I don't understand why there seems to be a problem with onSucce

World Time API call triggers onFailure instead of onSuccess

nzioker I'm trying to create a simple app that selects a time from an API, worldtimeapi and then displays it as soon as a button is clicked. However, when I click, the onFailure() method is fired. I don't understand why there seems to be a problem with onSucce

World Time API call triggers onFailure instead of onSuccess

nzioker I'm trying to create a simple app that selects a time from an API, worldtimeapi and then displays it as soon as a button is clicked. However, when I click, the onFailure() method is fired. I don't understand why there seems to be a problem with onSucce