I am trying to save the URL of an image by using the method below:
StorageReference filePath = imageStorage.child("profile_images").child(currentUserID + ".jpg");
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful())
{
String downloadURL = task.getResult().getStorage().getDownloadUrl().toString();
userDataBase.child("image").setValue(downloadURL).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
progressDialog.dismiss();
}
});
}
else
{
progressDialog.dismiss();
Toast.makeText(SettingsActivity.this, "Error Uploading",Toast.LENGTH_SHORT).show();
}
}
});
}
String downloadURL = task.getResult().getStorage().getPath();
userDataBase.child("image").setValue(downloadURL).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
progressDialog.dismiss();
}
});
}
else
{
progressDialog.dismiss();
Toast.makeText(SettingsActivity.this, "Error Uploading",Toast.LENGTH_SHORT).show();
}
}
});
I am using Firebase API in Android Studio. What I am trying to do is to upload an image by the user and save the URL to the database so later I can retrieve it from there. But the method getDownloadUrl() does not return the URL, it returns this string instead:
com.google.android.gms.tasks.zzu@302097b