【发布时间】:2020-03-20 19:32:57
【问题描述】:
我正在使用 java 开发一个 android 应用程序,我正在使用 cloud firestore 和 firebase storage 来存储用户的个人资料图片。 当用户登录时,他/她可以上传个人资料图片并将其加载到 imageView 中, 图片成功上传到storage并成功加载到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);
}
});
【问题讨论】:
-
请编辑问题以更详细地解释究竟是什么不符合您的预期。有什么失败吗?有错误吗?你做了什么来调试这个?
-
我会注意,这不会给你一个你可以用毕加索加载的 URL:
String Link = mImageUri.toString(); -
没有错误也没有异常,我给你一个场景来理解
-
1- 用户登录 2- 用户上传个人资料图片 3- 用户图片加载到 imageView 4- (我的开发人员)重新运行应用程序 5- 用户登录 2- 用户图片为空(无法加载)。
标签: java android firebase google-cloud-firestore google-cloud-storage