A
A
AndreyRafalsky132019-03-15 12:57:58
Android
AndreyRafalsky13, 2019-03-15 12:57:58

Why do I get an exception when getting the url after saving the image in FirebaseStorage?

Good afternoon. Help me to understand. You need to put an image in FirebaseStorage and then put the url to this image in the database. Wrote a method:

public void updateProfileImage(Uri resultUri) {
        storage.getReference().child(StorageConstants.PROFILE_IMAGES_DIR_NAME).child(getCurrentFirebaseUser().getUid()+".jpg").putFile(resultUri)
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()){
                        db.collection(UserCollection.COLLECTION_NAME).document(getCurrentFirebaseUser().getUid())
                                .update(UserCollection.UserDocument.PROFILE_FIELD, task.getResult().getStorage().getDownloadUrl())
                                .addOnSuccessListener(aVoid -> {
                                    status.postValue(Status.IMAGE_UPDATED);
                                    updateUser();
                                })
                                .addOnFailureListener(e -> status.postValue(Status.SOMETHING_WRONG));
                    }else{
                        status.postValue(Status.SOMETHING_WRONG);
                    }
                });
    }

I get the Caused by: java.lang.IllegalStateException: Task is not yet complete exception when I try to get the url and put it in the document.
In what a problem I will not understand in any way. Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
123 135, 2019-03-22
@Bogdan24

Perhaps the problem is in the ".jpg" in the second line. Try this

storage.getReference().child(StorageConstants.PROFILE_IMAGES_DIR_NAME).child(getCurrentFirebaseUser().getUid()).putFile(resultUri)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question