Skip to content Skip to sidebar Skip to footer

Get Saved Key In Firebase As Soon As Object Is Saved

I'm new to Firebase and I've come so far with Firebase so far. Like saving objects and retrieving object. I want to know how to get the key of the object saved. In hibernate, it re

Solution 1:

DatabaseReference.push() is a pure client-side operation that returns a reference to a new location that is statistically guaranteed to be unique. So you can first run that and get the key from it, then create a storage reference based on that key:

DatabaseReferencenewDatabaseRef= ref.child("Advertisements").push();
StorageReferencenewStorageRef= mStorageReference.child("advertisement").child(newRef.getKey()).child(uri.getLastPathSegment());

And then finally set the value to the database and put the file to storage:

newDatabaseRef.setValue(mobileAdd);
newStorageRef.putFile(uri);

Post a Comment for "Get Saved Key In Firebase As Soon As Object Is Saved"