How do I know if a file exists in Storage Firabase?

0

I am using Firebase Storage to store user profile photo, I made a method to fetch the image and put it in an ImageView. It works great when the image exists in Firebase, but when it does not exist, it leaves ImageView with nothing, neither the standard image that I put in XML appears. How do I handle when the method does not return an image?

private void buscarFotoPerfil(String idUsuario) {

    try {
        storage = ConexaoFirebase.getStorageReference()
                .child("images/perfil/" + idUsuario + ".jpg");

        Glide.with(this)
                .using(new FirebaseImageLoader())
                .load(storage)
                .into(imagePerfil);

    } catch (Exception e) {
        Toast.makeText(this, "Erro ao carregar foto do perfil." + e, Toast.LENGTH_SHORT).show();
    }
}
    
asked by anonymous 29.08.2017 / 02:05

1 answer

0

You can use the placeholder() method while loading the image and the error() method in the event of an error in loading the image. See:

Glide 4.x :

GlideApp.with(this)
    .using(new FirebaseImageLoader())
    .load(storage)
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imagePerfil);

Glide 3.x :

Glide.with(this)
    .using(new FirebaseImageLoader())
    .load(storage)
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imagePerfil);
    
29.08.2017 / 04:00