java - 从云存储中检索用户图像到 Imageview
问题描述
我正在使用 java 开发一个 android 应用程序,我正在使用 cloud firestore 和 firebase storage 来存储用户的个人资料图片。当用户登录时,他/她可以上传个人资料图片并将其加载到imageView中,图像成功上传到存储并成功加载到imageView中。
但是,当我重新运行应用程序并登录我上传图片的帐户时,无法像以前那样将图片加载到 imageView 中。
这是我上传图片的代码:
if (mImageUri != null){
file = mStorageRef.child(userId+".png");
UploadTask = file.putFile(mImageUri).addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(EditDonatorProfile.this,"Image uploaded successfully",Toast.LENGTH_SHORT).show();
String Link = mImageUri.toString();
Upload upload = new Upload(userId,Link);
db.collection("profilePicture").document(userId).set(upload);
}
});
}
else
{
Toast.makeText(this,"Choose a file first",Toast.LENGTH_SHORT).show();
}
这是我的检索代码:
DocumentReference documentReference1 =db.collection("profilePicture").document(userId);
documentReference1.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
String uri = documentSnapshot.getString("link");
StorageReference storageReference = StorageReference.getReference("Images/"+userId+".png");
if(uri == null)
return;
Uri link = Uri.parse(String.valueOf(uri));
Picasso.with(DonatorProfile.this).load(link).into(Photo);
}
});
解决方案
getCurrentUser().updateProfile(new UserProfileChangeRequest.Builder().setPhotoUri().build());
推荐阅读
- mediawiki - 如何使用 PluggableAuth - Mediawiki 接收 POST 数据?
- python - 如何为 Pytesseract 处理这个图像?
- node.js - 保存时对象的 Mongoose 数组为空
- python - Python Asyncio:GET 调用在 FPL API 端点上返回空响应
- c - 客户端关闭套接字连接后服务器挂在recv方法上
- sql - 如何获取具有位置的员工每天的最小和最大日期?
- tensorflow - 批处理结束后如何更改 Tensorflow 中的学习率?
- python - 在 python 包 install_requires 中指定“或”
- python - seaborn FacetGrid 垂直轴上的分层标签
- python - Python 到 C++ 通信失败