I tried to get a download URL like this but it is not getting correct URL. I am a beginner in Firebase, how can I do it?
Asked
Active
Viewed 1,413 times
2 Answers
2
You can get the download URL like this
fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
final Uri download_url = uri;
}
}):

Rohit Singh
- 16,950
- 7
- 90
- 88

Ashwith Saldanha
- 1,700
- 1
- 5
- 15
0
You can get your download path after uploading the file as follows (you need to call a second method on your reference object (getDownloadUrl
):
profilePicUploadTask = fileRef.putFile(imgUrl).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
{
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
{
// note: you can get the download path only after the file is uploaded successfully.
// To get the download path you have to call another method like follows:
fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
{
@Override
public void onSuccess(Uri uri)
{
// uri is your download path
}
}
});

kAliert
- 768
- 9
- 21
-
Thank you. But it also not working :-( can not put putFile to profilePicUploadTask – Sampath Jan 14 '19 at 09:01
-
@Sampath see my edited answer. You need to use `fileRef.putFile()` and `fileRef.getDownloadUrl()` – kAliert Jan 14 '19 at 09:26
-