When I try to upload an image onto firebase, the image url is something like "com.google.android.gms.tasks.zzw@f6699b3" instead of "https://firebasestorage.googleapis.com/...". The image itself uploads to Firebase Storage just fine, but issue right now is with the imageUrl in Realtime Database.
Below is my addToDatabase method.
private void addToDatabase(String familyName, String titleTxt, String descrptnTxt, String pointsTxt, String status) {
if(mImageUri != null){
StorageReference fileReference = mStorageRef.child(System.currentTimeMillis()
+ "." + getFileExtension(mImageUri));
mUploadTask = fileReference.putFile(mImageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String choreId = mRootRef.child("FamilyFunctions").child(familyName).child("Chores").push().getKey();
Chores chore = new Chores(assignedTo, descrptnTxt, choreId, mStorageRef.getDownloadUrl().toString(), pointsTxt, status, titleTxt);
// Chores chore = new Chores(titleTxt, descrptnTxt, pointsTxt, status, choreId, taskSnapshot.getMetadata().getReference().getDownloadUrl().toString(), assignedTo);
mRootRef.child("FamilyFunctions").child(familyName).child("Chores").child(choreId)
.setValue(chore).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(PostActivity.this, "Chore successfully created!", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(PostActivity.this, "Error. Couldn't add chore.", Toast.LENGTH_SHORT).show();
}
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(PostActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
} else {
Toast.makeText(this, "No file selected", Toast.LENGTH_SHORT).show();
}
Below is my chores model:
public class Chores {
public String assignedTo;
public String description;
public String id;
public String imageUrl;
public String pointsWorth;
public String status;
public String title;
public Chores() {
}
public Chores(String assignedTo, String description, String id, String imageUrl, String pointsWorth, String status, String title) {
this.assignedTo = assignedTo;
this.description = description;
this.id = id;
this.imageUrl = imageUrl;
this.pointsWorth = pointsWorth;
this.status = status;
this.title = title;
}
//getters and setters etc.
//...
}
I have tried other methods of writing "mStorageRef.getDownloadUrl().toString()"
and changing it to taskSnapshot.getMetadata().getReference().getDownloadUrl()
but so far nothing else has worked, and I'm trying to avoid rewriting all of my code. Can someone please help me??