代码中将文件上传到Firebase存储的两个任务是什么?

根据文档Upload Files on Android,这是将文件上传到Firebase存储并检索下载uri的代码:

    Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.Tasksnapshot,Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.Tasksnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }

        // Continue with the task to get the download URL
        return ref.getDownloadUrl();
    }
    }).addOnCompleteListener(new OnCompleteListener<Uri>() {
        @Override
        public void onComplete(@NonNull Task<Uri> task) {
            if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
            } else {
                 // Handle failures
                 // ...
            }
        }
    });

从代码中可以看到,代码中有两个任务,Task<UploadTask.Tasksnapshot>方法上的continueWithTask任务和Task<Uri>方法上的addOnCompleteListener的任务。我想知道我必须检查哪个任务以确保文件成功上传?

lms886 回答:代码中将文件上传到Firebase存储的两个任务是什么?

Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot,Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }

        // Continue with the task to get the download URL
        return ref.getDownloadUrl();
    }
    }).addOnCompleteListener(new OnCompleteListener<Uri>() {
        @Override
        public void onComplete(@NonNull Task<Uri> task) {
            if (task.isSuccessful()) {
                -> **This is the Success Case for you**
                Uri downloadUri = task.getResult();
            } else {
                 -> **In this case File Uploaded Successfully But You failed to get its URL,Again send this call again with storage reference. No need to send other 
                   call to upload the file again because its uploaded already on FireStore.**
                }
            }
        });
本文链接:https://www.f2er.com/3046668.html

大家都在问