Register user with photo on firebase

1

Good evening!   Personally, I am making a user registry in my app and would like in addition to the personal data that I will save in the realtime database I would like to save the profile photo and a cover photo (or it can be just the profile picture itself), but I do not know how to create the user in the database and link this photo to when I will bring the profile data. Could you guide me with some code example or some link that can help me? Thanks!

    
asked by anonymous 02.09.2017 / 01:20

1 answer

3

I would advise you to use AUTH firebase, to authenticate your user and use facebook profile photo, or google + automatically. But if you want to use a photo chosen by the user, you should use firebase Storage, when to send the message to the database, you will send the user image to the firebase storage, and retrieve that url on your user's node at the same time.If you do this free course, you will be able to do this operation quietly: course firebase wekend

What you'll see in 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);

                    }
    
02.09.2017 / 06:29