总而言之,我想在 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/