taskSnapshot.getDownloadUrl()方法不起作用 [英] taskSnapshot.getDownloadUrl() method not working

查看:123
本文介绍了taskSnapshot.getDownloadUrl()方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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()方法不起作用,其下方显示红线

taskSnapshot.getDownloadUrl() method not working comes up with red line under it

推荐答案

编辑:请参见

Edit: see this comment on why the approach in this answer doesn't work:

firebaser here 这个答案是错误的.尽管起初它似乎可以工作(因为它可以编译),但getDownloadUrl().toString()的结果不是下载URL,而是Task对象的字符串表示形式.要获得更好的答案,请参见 stackoverflow.com/a/55503926

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.

下面的原始答案...

Original answer below...

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

In Firebase Storage API version 16.0.1, the getDownloadUrl() method using taskSnapshot object has changed. now you can use,

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

从Firebase存储中获取下载URL.

to get download url from the firebase storage.

这篇关于taskSnapshot.getDownloadUrl()方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆