Skip to content
Advertisement

When uploading a image for one user to firebase storage, the link of the image updates for every user in database

I’m creating this app in Android Studio using Firebase Realtime Database and Firebase Storage. When a user registers through my app the data will store in the Firebase Realtime Database. Then on the profile page, there is a place to upload a picture. When a user uploads a picture it will store in the firebase storage and the link will update in the database on a new field under the respective user.

It worked correctly the last time I checked. But when I added a new user and uploaded his profile picture, that link updates on every other user as well. But in the Firebase Storage, there were no changes. It only happens in Firebase Realtime Database. I couldn’t find any solution to this.

This is the part I update the link of the profile.

JavaScript

here usrRf = FirebaseDatabase.getInstance().getReference(“users”);

Here is my database structure

Any help will be appreciated. Thank you.

Advertisement

Answer

According to your last comment:

Yes, Firebase email Authentication

Then you should consider saving user data, under the UID that comes from the authentication process and not under a pushed ID, as I see in your screenshot now. This means that you should add a User object to the database using:

JavaScript

And not using:

JavaScript

That beeing said, to be able to update the image that is uploaded to the node of the logged-in user, then please use the following updated method:

JavaScript

See, there is no for-loop involed? That was causing you trouble, as it was updating all child under “users” node.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement