How to place a Firebase generated url into an ImageView with Glide? [duplicate]

℡╲_俬逩灬. 提交于 2020-04-01 02:46:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!