【发布时间】:2019-01-18 04:29:32
【问题描述】:
我正在使用太多开发人员推荐的方法来检索存储在 firebase 存储中的图像的Uri,这是我的代码:
final StorageReference filereference = storageReference.child(System.currentTimeMillis()
+"."+getFileExtension(imageUri));
uploadTask =filereference.putFile(imageUri);
uploadTask.continueWith(new Continuation<UploadTask.TaskSnapshot,Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws
Exception {
if(!task.isSuccessful()){
throw task.getException();
}
return filereference.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if(task.isSuccessful()){
try{
Uri downloadUri = task.getResult();
String mUri =downloadUri.toString();
}catch (Exception e){
Log.e("testingerror",e.toString());
}
它向我抛出了这个错误: com.example.asus.fireapp E/stayinsh: java.lang.ClassCastException: com.google.android.gms.tasks.zzu 无法转换为 android.net.Uri
【问题讨论】:
-
您正在使用不再存在的 API。
-
嗨,Doug,我很困惑,我实际上是在使用文档中的 google 代码:firebase.google.com/docs/storage/android/…
-
@joghm 上传任务是否有效?
-
上传工作正常,是的
-
顺便说一句,您链接到的示例使用的是 continueWithTask,而不是 continueWith。
标签: android firebase firebase-storage