问题
So when I upload an image onto Firebase Storage, the getDownloadUrl()
method generates a string such as: com.google.android.gms.tasks.zzu@275cc4
Now I'm trying to place the image uploaded into an ImageView
:
ImageView img;
img = v.findViewById(R.id.imgView);
Glide.with(getApplicationContext()).load("com.google.android.gms.tasks.zzu@275cc4").into(img);
This doesn't seem to load the image. I tried with the full firebase url https://firebasestorage.googleapis.com/v0/.....
and this worked, but I can't seem to find a method that generates this when I upload an image?
回答1:
storageRef.child(path).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Glide.with(getApplicationContext()).load(uri.toString()).into(img);
}
});
Hope this will help you.......Have a nice day
回答2:
To solve this, you need to pass to the load()
method the actual url of the photo. I'm affraid:
com.google.android.gms.tasks.zzu@275cc4
Is not a valid url for an image. So change the above url with one that is correct formated and includes: https://firebasestorage.googleapis.com/v0/...
.
To verify if the url is correct, just copy and paste that url in a browser and see if it opens an image. If it doesn't open, it means that you have provided an incorrect url.
来源:https://stackoverflow.com/questions/52651815/how-to-place-a-firebase-generated-url-into-an-imageview-with-glide