Error: cannot find symbol method getDownloadUrl() of type com.google.firebase.storage.UploadTask.TaskSnapshot

后端 未结 7 866
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 07:28

Before gradle update everything worked fine, but later on this error popped up. I have referred to the official documents and it provides the same code. Not accepting the ge

7条回答
  •  执笔经年
    2020-11-29 08:21

    getDownloadUrl no longer exists.

    So the new method is:

    final StorageReference ref = storageRef.child("images/mountains.jpg");
    uploadTask = ref.putFile(file);
    
    Task urlTask = uploadTask.continueWithTask(new Continuation>() {
        @Override
        public Task then(@NonNull Task task) throws Exception {
            if (!task.isSuccessful()) {
                throw task.getException();
            }
    
            // Continue with the task to get the download URL
            return ref.getDownloadUrl();
        }
    }).addOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(@NonNull Task task) {
            if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
            } else {
                // Handle failures
                // ...
            }
        }
    });
    

    Firebase doc

提交回复
热议问题