question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UploadTask.TaskSnapshot doesn't have getDownloadUrl() method

See original GitHub issue

I’m following a tutorial teaching how to upload images to Firebase. At certain moment the instructor will write the code to get the download URL after uploading by using getDownloadUrl() method from UploadTask.TaskSnapshot, but for me, this method doesn’t exist.

enter image description here

Based on another code I found, I tried the following:

OnSuccessListener<UploadTask.TaskSnapshot> upload = new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        ChatroomMessage message = new ChatroomMessage(null, mUsername, taskSnapshot.getDownloadUrl());
        mMessagesDatabaseReference.push().setValue(message);
    }
};

Because it is similar to what’s shown in the documentation, but I didn’t understand it very well. How to implement it?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:41

github_iconTop GitHub Comments

123reactions
LucaUburticommented, May 31, 2018

Yes they deprecated and then removed that method. I use the following code, similar to what is written in the docs.

photoStorageReference.putFile(selectedImageUri).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();
        }
        return photoStorageReference.getDownloadUrl();
    }
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
        if (task.isSuccessful()) {
            Uri downloadUri = task.getResult();
            FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUri.toString());
            mMessagesDatabaseReference.push().setValue(friendlyMessage);
        } else {
            Toast.makeText(MainActivity.this, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
});

38reactions
Parthav46commented, Jun 18, 2018
taskSnapshot.getStorage().getDownloadUrl().toString()

@DevRyz3n running this command would raise FileNotFoundException as the returned value is not the download url for file. Instead try this code where I have created a Task object to perform getDownloadUrl() task, waited for its completion in the main thread and then obtained the URL through getResult() function.

@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
     Task<Uri> urlTask = taskSnapshot.getStorage().getDownloadUrl();
     while (!urlTask.isSuccessful());
     Uri downloadUrl = urlTask.getResult();
     FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
     mDatabaseReference.push().setValue(friendlyMessage);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

taskSnapshot.getDownloadUrl() method not working
In Firebase Storage API version 16.0.1, the getDownloadUrl() method using taskSnapshot object has changed. now you can use, taskSnapshot.
Read more >
UploadTask.TaskSnapshot | Firebase - Google
class UploadTask.TaskSnapshot : StorageTask.SnapshotBase ... Encapsulates state about the running UploadTask. Summary. Public constructors. TaskSnapshot() ...
Read more >
Android – taskSnapshot.getDownloadUrl() method not working
firebaser here This answer is wrong. While it at first may appear to work (since it compiles) the result of getDownloadUrl().toString() is not...
Read more >
What do I use instead of .getdownloadurl in android firebase?
Solved: I changed. Java. Uri firebaseUri = taskSnapshot.getDownloadUrl(); to. Java. Task<Uri> firebaseUri = taskSnapshot.getStorage().
Read more >
Upload files with Cloud Storage on Flutter - FlutterFire
After uploading a file, you can get a URL to download the file by calling the getDownloadUrl() method on the Reference : await...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found