I am trying to add an image to the user information in the real time database(firebase) for android. I have uploaded the image on the firebase storage but how will I be able to
Just to update because I spent sometime to find this answer, getDownloadUrl()
is NOT a function of taskSnapshot
anymore. So in order to get the image URL from Firebase Storage you need to add a listener to
taskSnapshot.getMetadata().getReference().getDownloadUrl()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==request_code&&resultCode==RESULT_OK){
Uri uri=data.getData();
StorageReference filepath=mStorage.child("Images").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
taskSnapshot.getMetadata().getReference().getDownloadUrl()
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Uri uri) {
newStudent.child("image").setValue(uri);
}
});
}
});
}
}
Now it's safe to use uri to whatever you want