gpt4 book ai didi

android - 如何检查 Firebase 存储中是否存在图像?

转载 作者:行者123 更新时间:2023-11-29 17:01:11 25 4
gpt4 key购买 nike

总而言之,我想在 Firebase 中为每个用户存储和检索个人资料图片。我正在尝试使用 FirebaseUI 和 Glide 从 Firebase 检索图像(如 here 所述)。

它非常适合我想要实现的目标,但我想处理用户没有上传自己的个人资料图片(当 Firebase 存储中没有图片时)的情况。遗憾的是,我无法找到如何检查 Firebase 存储中是否存在这样的文件。有谁知道如何检查是否有文件 profile.jpg

(在 Firebase 存储中)在以下代码中?

StorageReference storageRef =  storageReference.child("profile.jpg");

ImageView imageView = profilePicture;
// Load the image using Glide
Glide.with(context /* context */)
.using(new FirebaseImageLoader())
.load(storageRef)
.into(imageView);

最佳答案

要在 firebase 上没有 'profile.jpg' 时显示默认图片,在较新的 v4 Glide 中,您可以使用 RequestOptions,如下所示:

RequestOptions options = new RequestOptions().error(R.drawable.default_avatar);
Glide.with(context /* context */)
.using(new FirebaseImageLoader())
.load(storageRef)
.apply(options)
.into(imageView);

Glide v3 的原始答案

使用报错方法:

Glide.with(context /* context */)
.using(new FirebaseImageLoader())
.load(storageRef)
.error(R.drawable.default_avatar)
.into(imageView);

关于android - 如何检查 Firebase 存储中是否存在图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42891058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com