I would like to save a profile picture of a user in my database and to use it later.
I saved it to my firebase cloud storage with this code :
private void uploadImage() {
if(picture != null)
{
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference ref = storageReference.child("images"+ UUID.randomUUID().toString());
ref.putFile(picture)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Uploaded", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded "+(int)progress+"%");
}
});
}
}
Now, I want to save it as a child in my Database... I have this code to save all the datas (Name, email, phone, password...)
mAuth.createUserWithEmailAndPassword(edtEmail.getText().toString(), edtPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
User user = new User();
user.setEmail(edtEmail.getText().toString());
user.setPhone(edtPhone.getText().toString());
user.setPassword(edtPassword.getText().toString());
user.setName(edtName.getText().toString());
user.setId(mAuth.getCurrentUser().getUid());
user.setProfilePic(picture);
But the "user.setProfilePic(picture)" doesn't work...
What could be the best way to save the profile picture of the user on my database ?
Thank you