and-nd-firebase: UploadTask.TaskSnapshot doesn't have getDownloadUrl() method
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.
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?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 11
- Comments: 41

Yes they deprecated and then removed that method. I use the following code, similar to what is written in the docs.
@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.
Try this, works good !!! believe me… put this in the onActivityResult method…😃
@ChutiBro try this
` package com.google.firebase.udacity.friendlychat;
import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.Toast;
import com.google.android.gms.tasks.Continuation; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.database.ChildEventListener; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.firebase.ui.auth.AuthUI; import com.google.firebase.storage.FirebaseStorage; import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.UploadTask;
import java.util.ArrayList; import java.util.Arrays; import java.util.List;
public class MainActivity extends AppCompatActivity {
}`
I use this code. but it does not store the photos in firebase. Not showing anything, but the app is not crashed. Help me to fix this.
<del>Try this <del> @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { FriendlyMessage message = new FriendlyMessage(null, mUsername , taskSnapshot.getStorage().getDownloadUrl().toString()); mMessagesDatabaseReference.push().setValue(message); }
<del>// FriendlyMessage(), the third parameter taskSnapshot.getStorage().getDownloadUrl().toString() </del>
I try to do it like this ↓↓↓ can work. Thanks @Parthav46
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() { @Override public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) { if(task.isSuccessful()){ Toast.makeText(SettingActivity.this,“Your picture Saved successfully”,Toast.LENGTH_SHORT) .show(); String DownloadUrl=task.getResult().getStorage().getDownloadUrl().toString();
Have a look here.
Its as simple as using your storageRef to get the download url on condition the task was successfull.
Note the
In place of
This solution works best! for getting the photos to upload and store in the database! 😃 The .getDownloadURL is no longer available and deprecated.
i am currently having the same problem
public class FirebaseStorageHelper {
}
Just write this:- Uri downloaduri=taskSnapshot.getStorage().getDownloadUrl().getResult();
I got it with this solution Check my code:
this code working in angular8
uploadfile(event:any){
const storageRef:firebase.storage.Reference =firebase.storage().ref(‘/photos’) const Uploadtask= storageRef.put(file) console.log(file.name)
}
thanks 1000 times Parthav46 I took your code and change it a litle bit and it works!!
private StorageReference userProfileImageRef;
userProfileImageRef = FirebaseStorage.getInstance().getReference().child( “Images” );
final StorageReference filePath = userProfileImageRef.child( userId + “.jpg” ); filePath.putFile( selectedImage ) .addOnSuccessListener( new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl(); while (!uriTask.isSuccessful()); Uri downloadUrl = uriTask.getResult(); String dw = downloadUrl.toString(); Toast.makeText( ProfilActivity.this,dw,Toast.LENGTH_LONG ).show(); DocumentReference documentReference = fFirestore.collection(“users”).document(userId); Map<String,Object> data = new HashMap<>(); data.put( “Slika”,dw ); fFirestore.collection( “users” ).document(userId).set( data,SetOptions.merge() );
I faced the same problem but I got the answer
Just add
.getStorage()infront of.getDownloadurlto be like this below
LEAVE EVERYTHING IN THAT LINE DONT ALTER JUST ADD
.getStorage()