【发布时间】:2019-07-08 10:46:49
【问题描述】:
代码成功地将图像上传到 Firebase 存储,但没有返回下载 URL。我该如何解决这个问题?
我得到这个异常:java.lang.IllegalArgumentException: getDownloadUrl() is not supported at the root of the bucket. 为什么?
private void uploadFile() {
if (mImageUri != null) {
StorageReference fileReference = mStorageRef.child(System.currentTimeMillis()
+ "." + getFileExtension(mImageUri));
fileReference.putFile(mImageUri).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 mStorageRef.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
System.out.println("Upload success: " + downloadUri);
} else {
// Handle failures
// ...
}
}
});
} else {
Toast.makeText(this, "No file selected", Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
-
你在哪里得到错误,在 xml 中?
-
你想在哪里找到它
-
你想如何添加?
-
带有@Style 属性?
标签: java android firebase firebase-storage