I searched a lot of questions on stack overflow, looking for an answer to this, but none of them are working for me.
I am using a code like following to upload an image from user's device to Firebase storage, and along with that, update the imageURL
node in firebase with URL of the image uploaded.
private void uploadFile(Bitmap bitmap) {
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRef = storage.getReference();
final StorageReference ImagesRef = storageRef.child("images/"+mAu.getCurrentUser().getUid()+".jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = ImagesRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.i("whatTheFuck:",exception.toString());
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onSuccess(final UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Task<Uri> downloadUrl = taskSnapshot.getMetadata().getReference().getDownloadUrl();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("users").child(mAu.getCurrentUser().getUid());
Log.i("seeThisUrl", downloadUrl.toString());
ref.child("imageURL").setValue(downloadUrl.toString());
}
});
But the imageURL is always not what I am expecting, it is something of the form:
com.google.android.gms.tasks.zzu@51bc124
instead of actual URL, and I am not able to find an answer to why it's happening like that.