1

I am building chat functionality withing an app using firebase. Everything works except for fetching images from storage. The image gets uploaded successfully but the downloadURl stored in the database for all images is always com.google.android.gms.tasks.zzu@7e17eff. The image is fetched if I manually change the download link in the database after copying it from firebase storage.

Method which handles firbase upload

private void putImageInStorage(final StorageReference storageReference, Uri uri, final String key) {
    storageReference.putFile(uri).addOnCompleteListener(
            new OnCompleteListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                    if (task.isSuccessful()) {
                        message friendlyMessage =
                                new message(null, mUsername, mPhotoUrl,
                                       task.getResult().getStorage().getDownloadUrl().toString() , mFirebaseUser.getUid());
                        mFirebaseDatabaseReference.child(MESSAGES_CHILD).child(key)
                                .setValue(friendlyMessage);
                    } else {
                        Log.w(TAG, "Image upload task was not successful.",
                                task.getException());
                    }
                }
            });
}

In the above code message (friendlyMessage) is a pojo for the firebaseRecycler.

The Firebase dependencies I am for the app.

implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
dabreo
  • 53
  • 1
  • 9

1 Answers1

-1

The getDownloadUrl() method using taskSnapshot object has changed. So, use

task.getMetadata().getReference().getDownloadUrl().toString() 

instead of -

task.getResult().getStorage().getDownloadUrl().toString()
Raj
  • 2,997
  • 2
  • 12
  • 30