Register user with photo in firebase

Asked

Viewed 3,814 times

2

Good night! Guys, I’m registering users in my app and would like to in addition to the personal data I will save in the database Realtime I would like to also save the profile photo and a cover photo(or it may just be the same profile photo)but I don’t know how to create the user in the database and link this photo to when I bring the profile data. Could you walk me through some example code or some link that might help me? Thank you!

1 answer

4


I would advise you to use firebase AUTH, to authenticate your user and use your facebook, or google+ profile photo automatically. But if you want to use a photo chosen by the user, you must use firebase Storage,and retrieve that url from your user’s node at the same time.If you do this free course,:firebase wekend course

What you’ll see on the course:

 Uri selectedImageUri = data.getData();

//      Get a reference to store file at firebase storage/<FILENAME>

        StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());

//      Upload file to Firebase Storage

        photoRef.putFile(selectedImageUri)

                .addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {

                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

//  When the image has successfully uploaded, we get its download URL

                        Uri downloadUrl = taskSnapshot.getDownloadUrl();




// Set the download URL to the message box, so that the user can send it
// to the database

                        FriendlyMessage friendlyMessage = new FriendlyMessage(TEXTO, NOME-DO-USUÁRIO, downloadUrl.toString(),DADOS-DO-USUÁRIO.............);
                        mMessagesDatabaseReference.push().setValue(friendlyMessage);

                    }
  • Thank you very much Oto! Sensational the tip of the course and the excerpt of the code, helped me and for sure will be very useful for other people too !

  • Hello. To use with Ionic 3 would have some example?

  • unfortunately not @Ezequieltavares ,I do not use this development platform.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.