How to get download URL in String from firebase storage inside "addOnSuccessListener"


Alif Hasnain |

This is how I upload the image file and get the download link

UploadTask uploadTask = profileImageRef.putBytes(data);
        uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                String fileUrl = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();

                Toast.makeText(UserProfile.this, "Uploaded Successfully!", Toast.LENGTH_SHORT).show();
            }});

When i log in fileUrlit shows a string like this

com.google.android.gms.tasks.zzu@6ee8ba8

Someone please give me a solution to get the download url.

Herman N. Kammer

you can use this

UploadTask uploadTask = profileImageRef.putBytes(data);

    Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }

        // Continue with the task to get the download URL
        return profileImageRef.getDownloadUrl();
    }
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
        if (task.isSuccessful()) {
            Uri downloadUri = task.getResult();
        } else {
            // Handle failures
            // ...
        }
    }
});

Related


How to remove query string from Firebase Storage download URL

Israel question: I need to be able to remove all link decorations from download URLs generated for images in Firebase Storage. However, when all link decorations are stripped, the currently generated link will return a JSON document of image metadata. content:

How to remove query string from Firebase Storage download URL

Israel question: I need to be able to remove all link decorations from download URLs generated for images in Firebase Storage. However, when all link decorations are stripped, the currently generated link will return a JSON document of image metadata. content:

How to remove query string from Firebase Storage download URL

Israel question: I need to be able to remove all link decorations from download URLs generated for images in Firebase Storage. However, when all link decorations are stripped, the currently generated link will return a JSON document of image metadata. content:

How to remove query string from Firebase Storage download URL

Israel question: I need to be able to remove all link decorations from download URLs generated for images in Firebase Storage. However, when all link decorations are stripped, the currently generated link will return a JSON document of image metadata. content:

Get download URL from Firebase Storage in Angular

Monther I'm trying to get the download URL after uploading a file to Firebase Storage, so far I've been able to upload the file, but for the URL, I've been getting undefined, this is my code: onFileChanged(event) { const file: File = event.target.files[0];

Unable to get download url from firebase storage

Pannan I can upload the image successfully but can't get the URL of the uploaded image Also with the recent changes to the method I would like to write a cleaner code than this. try { await FirebaseStorage.instance .ref()

Get download URL from Firebase Storage in Angular

Monther I'm trying to get the download URL after uploading a file to Firebase Storage, so far I've been able to upload the file, but for the URL, I've been getting undefined, this is my code: onFileChanged(event) { const file: File = event.target.files[0];

Error trying to get download URL from firebase-storage

Alec Janiak I've been trying to get the download URL of an image in my firebase storage, but it keeps throwing object-does-not-exist errors. Any clue what could be the problem? I'm sure the directories match and there is a profilePhoto.jpg file in the firebase

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; } }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

Get download URL of Firebase Storage file

birdcage I have a mobile app that requires Firebase registration to backup/restore custom user data in Firebase. I would like to know if an authorized user can somehow get the url of his own stored file and download it to his computer. Frank Vampfelen If a use

The URL to download from Firebase Storage is empty

Mobilize IT I am using Ionic 4 to upload images from camera to firebase storage. The upload works fine, but I'm having trouble getting the upload URL. My code looks like this: async getFromCamera(){ this.camera.getPicture({ destinationType: this.came

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items