【发布时间】:2019-07-13 07:17:46
【问题描述】:
尝试使用 docs 获取上传到 Firebase 存储中的图像的 URL,但没有关于如何从 Task.continueWithTask 方法返回 downloadUri 值的信息。
即使method documentation 也无助于理解。
引用自文档,没有说明如何获取此 URL:
上传文件后,可以通过调用StorageReference的getDownloadUrl()方法获取下载文件的URL:
final StorageReference ref = storageRef.child("images/mountains.jpg");
uploadTask = ref.putFile(file);
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
// ...
}
}
});
【问题讨论】:
-
看来你写了获取下载地址的代码,所以我不太明白问题出在哪里。
-
我重写了my question,问题是
continueWithTask没有启动。你能帮忙吗?
标签: android firebase firebase-storage