android - taskSnapshot.getDownloadUrl() 方法不起作用

标签 android firebase-storage

private void uploadImageToFirebaseStorage() {
    StorageReference profileImageRef =
        FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

    if (uriProfileImage != null) {
        progressBar.setVisibility(View.VISIBLE);
        profileImageRef.putFile(uriProfileImage)
            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
                    progressBar.setVisibility(View.GONE);
                    profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    progressBar.setVisibility(View.GONE);
                    Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
    }
}

taskSnapshot.getDownloadUrl() 方法不工作,下面有红线

最佳答案

编辑:参见this comment为什么这个答案中的方法不起作用:

firebaser here This answer is wrong. While it at first may appear to work (since it compiles) the result of getDownloadUrl().toString() is not a download URL, but a string representation of a Task object. For a better answer, see stackoverflow.com/a/55503926 or the sample in the Firebase documentation.

下面是原始答案...


Firebase Storage API 版本 16.0.1 中, 使用 taskSnapshot 对象的 getDownloadUrl() 方法已更改。 现在你可以使用了,

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()

从 firebase 存储中获取下载 url。

关于android - taskSnapshot.getDownloadUrl() 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585334/

相关文章:

Android cursoradapter过滤器 ListView

ios - 从异步调用返回图像

firebase - Firebase 的云函数 : write to database on fileupload

android - 图片网址不会被推送到 Firebase 数据库

java - 拉普拉斯金字塔产生奇怪的结果?

Android:一个 Activity 中的多个 View

android - 在Android Project中不依赖Picasso

java - 在单独的类中加载 JSON 数组列表并在另一个 Activity 中加载

javascript - 如何将图像数组上传到 firebase 存储?

ios - Firebase iOS 存储图像