如果我以前已经下载过,如何避免从Firebase下载图像? [英] How to avoid downloading image from firebase if i have already downloaded previously?

查看:42
本文介绍了如果我以前已经下载过,如何避免从Firebase下载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试存储来自Firebase数据库的图像,并将其命名为FirebaseuniqUserID.jpeg.(例如buwkgefuikbuifbkc8gfybfy.jpeg).用户可以随时更改图像. 为了从Firebase实时数据库获取图像链接,我使用了addListenerForSingleValueEvent.

I am trying to store image from firebase database and named it FirebaseuniqUserID.jpeg.(like buwkgefuikbuifbkc8gfybfy.jpeg). And user can change image anytime. For getting image link from firebase realtime database i used addListenerForSingleValueEvent.

FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseuniqUserID).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        //here i am downloading image//
        //and named it FirebaseuniqUserID.jpeg
    }

现在的问题是,每次下载图像时都会调用此侦听器. 但是,如果当前用户在firebase中具有最新的用户映像,则现在我希望避免下载,以减少firebase下载的数据.

Now the problem is this when this listener is called every time image is download. But now i want avoid downloading if current user has latest updated image of user in firebase to reduce firebase downloaded data.

推荐答案

您可以使用两个不同的选项,第一个是 Glide 和第二个功能是,您可以将图像下载状态保存在本地数据库文件或SharePreferences中.但是图像缓存是最好的解决方案.

You can use two different options, first is Glide and 2nd is that, you can save image downloading status in your local database file or SharePreferences. But image cache is the best solution.

这篇关于如果我以前已经下载过,如何避免从Firebase下载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆