Hot questions for Using Glide in firebase storage

Top 10 Java Open Source / Glide / firebase storage

Question:

I'm trying to use Firebase integration with Glide and for some reason, Glide.using() cannot resolve this method. I did add:

compile 'com.firebaseui:firebase-ui-storage:0.6.0'

Into build.gradle and also:

compile 'com.github.bumptech.glide:glide:4.0.0-RC1'

Here is the part which I'm trying to use Glide:

   mStorageRef = FirebaseStorage.getInstance().getReference();
    mStorageRef.child("images/Puffer-fish-are-pretty-damn-cute.jpg");

// Load the image using Glide
        Glide.with(this)
                .using(new FirebaseImageLoader()) // cannot resolve method using!
                .load(mStorageRef)
                .into(imageView);

I hope you can help me with that, didn't find any solutions online.


Answer:

To solve this, please change this line:

compile 'com.github.bumptech.glide:glide:4.0.0-RC1'

with

compile 'com.github.bumptech.glide:glide:3.7.0'

Question:

I have made an social app for image and video sharing.However,its taking too much time for loading the image.I am using the glide library.Please, tell me how can I reduce the size of image picked up from gallery without considerable change in quality of image (like Instagram do) and then upload it to firebase storage.Please help!


Answer:

StorageReference childRef2 = [your firebase storage path]
storageRef.child(UserDetails.username+"profilepic.jpg");
                    Bitmap bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bmp.compress(Bitmap.CompressFormat.JPEG, 25, baos);
                    byte[] data = baos.toByteArray();
                    //uploading the image
                    UploadTask uploadTask2 = childRef2.putBytes(data);
                    uploadTask2.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            Toast.makeText(Profilepic.this, "Upload successful", Toast.LENGTH_LONG).show();
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(Profilepic.this, "Upload Failed -> " + e, Toast.LENGTH_LONG).show();
                        }
                    });`

just go ahead and do above steps it will reduce your image size and upload it on firebase it reduce the image size upto 1 to 2 mb like on my experience 4mb file became 304kb .

filepath is and File object of your selected image. :)

Question:

I am using firebase storage in my android app to store images uploaded by users. all images uploaded are square in shape. I discovered that downloading this images consumes a lot of user bandwidth and i would like to reduce this consumption by reducing the size of image downloaded into a square imageview

I am using Glide to download this images and i have tried to download images of custom size but the image is not appearing on the imageview.

interface

public interface MyDataModel {
  public String buildUrl(int width, int height);
}

my class which extends BaseGlideUrlLoader

public class MyUrlLoader extends BaseGlideUrlLoader<MyDataModel> {
  public MyUrlLoader(Context context) {
    super(context);
  }

  @Override
  protected String getUrl(MyDataModel model, int width, int height) {
    // Construct the url for the correct size here.
    return model.buildUrl(width, height);
  }
}

class which implements MyDataModel interface

public class CustomImageSize implements MyDataModel {

  private String uri;

  public CustomImageSize(String uri){
    this.uri = uri;
  }

  @Override
  public String buildUrl(int width, int height) {

    return uri + "?w=" + width + "&h=" + height;
  }
}

Finally

CustomImageSize size = new CustomImageSize(uri);

  Glide.with(context)
    .using(new MyUrlLoader(context))
    .load(size)
    .centerCrop()
    .priority(Priority.HIGH)
    .into(imageView);

RESULTS OF SOLUTION ABOVE

Image is not appearing in my square imageview

SOLUTION 2: use firebase image loader

    // Reference to an image file in Firebase Storage
StorageReference storageReference = ...;

ImageView imageView = ...;

// Load the image using Glide
Glide.with(this /* context */)
        .using(new FirebaseImageLoader())
        .load(storageReference)
        .into(imageView);

RESULT OF SOLUTION 2 ABOVE

working! image is appearing BUT it's like entire image is been downloaded which consume a lot of bandwidth. I just want a custom size image e.g 200px by 200px to be downloaded.

How can I do or change in my solution 1 above to download images of custom size from firebase storage?

EDIT

I have tried to access one of my images https://firebasestorage.googleapis.com/....m.png from the browser and it was loaded successfully to the webpage. but when i try to put to size specific parameters to my image url link https://firebasestorage.googleapis.com/....m.png?w=100&h=100 an error appeared on the webpage

 {
  "error": {
    "code": 403,
    "message": "Permission denied. Could not perform this operation"
  }
}

Answer:

I was finally able to download images from firebase storage using MyUrlLoader class

You see, firebase storage urls look like this

firebasestorage.googleapis.com/XXXX.appspot.com/Folder%2Image.png?&alt=media&token=XXX

As you can see above, the link already have this special question mark character ? which stands for the start of querying string so when i use CustomImageSize class, another ? was being added so the link was ending up with two ? which made downloading to fail

firebasestorage.googleapis.com/XXXX.appspot.com/Folder%2Image.png?&alt=media&token=XXX?w=200&h=200

Solution was to remove the ? in my CustomImageSize class. so it ended up like this

    public class CustomImageSize implements MyDataModel {

  private String uri;

  public CustomImageSize(String uri){
    this.uri = uri;
  }

  @Override
  public String buildUrl(int width, int height) {

    return uri + "w=" + width + "&h=" + height;
  }
}

Although it downloaded, am not sure whether entire image was being downloaded or just the custom size one. This is because, i tried to access the image in my browser after correcting the error that was making viewing to fail, but still i was receiving an entire image. not a resized image (w=200&h=200)

Question:

I am using Glide to fetch and display photos from Firebase Storage. Things work very well when the device is in online.

When the user updates profile picture (firebase storage reference changes), Glide fails to fetch photo from Firebase storage's offline cache.

I don't want to cache photo using Glide. I just want to retrieve the cached photo from Firebase storage's offline cache. Is there any possible way or workaround to solve this problem.

Here is my code.

Glide Module

@GlideModule
class MyGlideModule : AppGlideModule() {

    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        registry.append(StorageReference::class.java, InputStream::class.java,
            FirebaseImageLoader.Factory())
    }
}

Code to fetch profile picture from firebase storage

GlideApp.with(profileIcon.context)
                .load(customerPictureReference)
                .centerCrop()
                .placeholder(R.drawable.ic_profile_placeholder)
                .into(profileIcon)

Answer:

The issue is that Firebase is not caching images (see here for more details).

You should be able to configure Glide to cache the images locally, with something like (see here more):

@GlideModule
public class GiphyGlideModule extends AppGlideModule {
  @Override
  public void applyOptions(Context context, GlideBuilder builder) {
    builder.setMemoryCache(new LruResourceCache(10 * 1024 * 1024));
  }

  @Override
  public void registerComponents(Context context, Glide glide, Registry registry) {
    registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory());
  }
}

Then you only need to add: .diskCacheStrategy(DiskCacheStrategy.ALL) to your call. Something like:

GlideApp.with(profileIcon.context)
                .load(customerPictureReference)
                .diskCacheStrategy(DiskCacheStrategy.ALL) 
                .centerCrop()
                .placeholder(R.drawable.ic_profile_placeholder)
                .into(profileIcon) 

Another option that you can use is Picasso that will also cache the images.

To retrieve the image first from the local cache, and if it fails to try from online, you can use something like:

Picasso.with(getActivity())
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
    @Override
    public void onSuccess() {
      //..image loaded from cache
    }

    @Override
    public void onError() {
        //Try again online if cache failed
        Picasso.with(getActivity())
                .load(posts.get(position).getImageUrl())
                .error(R.drawable.header)
                .into(imageView, new Callback() {
            @Override
            public void onSuccess() {
              //... image loaded from online
            }

            @Override
            public void onError() {
                Log.v("Picasso","Could not fetch image");
            }
        });
    }
});

Question:

I'm having a hard time getting an image URL from firebase storage, I got the photo URL from the database, but as I know, Glide can't get a picture from the link like this: com.google.firebase.storage.UploadTask@62873ce

Here are my Storage and database references:

 private fun StorageReference.uploadUserPhoto(uid: String, photo: Uri,
                                             onSuccess: (UploadTask.TaskSnapshot) -> Unit) {
    child("users/$uid/photo").putFile(mImageUri).addOnCompleteListener {
        if (it.isSuccessful) {
            mStorage.child("users/$uid/photo").downloadUrl.addOnCompleteListener { task ->
                if (it.isSuccessful) {
                    onSuccess(it.result!!)
                } else {
                    showToast(it.exception!!.message!!)
                }
            }
        }
    }
}


private fun DatabaseReference.updateUserPhoto(uid: String, photoUrl: String,
                                              onSuccess: () -> Unit){
    child("users/$uid/photo").setValue(photoUrl)
        .addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                showToast(it.exception!!.message!!)
            }
        }
}

here is the function:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    if (requestCode == TAKE_PICTURE_REQUEST_CODE && resultCode == RESULT_OK) {
        val uid = mAuth.currentUser!!.uid
        mStorage.uploadUserPhoto(uid, mImageUri) {
            val photoUrl = it.task.toString()
            mDatabase.updateUserPhoto(uid, photoUrl) {
                mUser = mUser.copy(photo = photoUrl)
                profile_image.loadUserPhoto(mUser.photo)
            }
        }
    }
}

I tried changing

val photoUrl = it.task.toString()

to

val photoUrl = it.downloadUrl.toString()

but it highlights 'downloadUrl' as unresolved reference

Full code:

    package com.example.homeactivity.activities

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.text.Editable
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import com.example.homeactivity.R
import com.example.homeactivity.models.User
import com.example.homeactivity.views.PasswordDialog
import com.google.firebase.auth.AuthCredential
import com.google.firebase.auth.EmailAuthProvider
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import com.google.firebase.storage.UploadTask
import kotlinx.android.synthetic.main.activity_edit_profile.*
import java.io.File
import java.text.SimpleDateFormat
import java.util.*


class EditProfileActivity : AppCompatActivity(), PasswordDialog.Listener {

    private lateinit var mImageUri: Uri
    private lateinit var mStorage: StorageReference
    private val TAG = "EditProfileActivity"
    private lateinit var mUser: com.example.homeactivity.models.User
    private lateinit var mAuth: FirebaseAuth
    private lateinit var mDatabase: DatabaseReference
    private lateinit var mPendingUser: com.example.homeactivity.models.User
    private val TAKE_PICTURE_REQUEST_CODE = 1
    val simpleDateFormat = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_profile)
        Log.d(TAG, "onCreate")

        close_image.setOnClickListener { finish() }
        save_image.setOnClickListener { updateProfile() }
        change_photo_text.setOnClickListener { takeCameraPicture() }

        mAuth = FirebaseAuth.getInstance()
        mDatabase = FirebaseDatabase.getInstance().reference
        mStorage = FirebaseStorage.getInstance().reference

        mDatabase.child("users").child(mAuth.currentUser!!.uid)
            .addListenerForSingleValueEvent(ValueEventListenerAdapter {
                mUser = it.getValue(com.example.homeactivity.models.User::class.java)!!
                name_input.setText(mUser.name, TextView.BufferType.EDITABLE)
                username_input.setText(mUser.username, TextView.BufferType.EDITABLE)
                website_input.setText(mUser.website, TextView.BufferType.EDITABLE)
                bio_input.setText(mUser.bio, TextView.BufferType.EDITABLE)
                email_input.setText(mUser.email, TextView.BufferType.EDITABLE)
                phone_input.setText(mUser.phone?.toString(), TextView.BufferType.EDITABLE)
                profile_image.loadUserPhoto(mUser.photo)
            })
    }

    private fun takeCameraPicture() {
        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        if (intent.resolveActivity(packageManager) != null) {
            val imageFile = createImageFile()
            mImageUri = FileProvider.getUriForFile(
                this,
                "com.example.homeactivity.fileprovider",
                imageFile
            )
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri)
            startActivityForResult(intent, TAKE_PICTURE_REQUEST_CODE)
        }
    }

    private fun createImageFile(): File {
        val storageDir: File? = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
        return File.createTempFile(
            "JPEG_${simpleDateFormat.format(Date())}_",
            ".jpg",
            storageDir
        )
    }

    @SuppressLint("MissingSuperCall")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == TAKE_PICTURE_REQUEST_CODE && resultCode == RESULT_OK) {
            val uid = mAuth.currentUser!!.uid
            mStorage.uploadUserPhoto(uid, mImageUri) {
                val photoUrl = it.task.toString()
                mDatabase.updateUserPhoto(uid, photoUrl) {
                    mUser = mUser.copy(photo = photoUrl)
                    profile_image.loadUserPhoto(mUser.photo)
                }
            }
        }
    }


    private fun updateProfile() {
        mPendingUser = readInputs()
        val error = validate(mPendingUser)
        if (error == null) {
            if (mPendingUser.email == mUser.email) {
                updateUser(mPendingUser)
            } else {
                PasswordDialog().show(supportFragmentManager, "password_dialog")
            }
        } else {
            showToast(error)
        }
    }


    private fun readInputs(): User {
        return User(
            name = name_input.text.toString(),
            username = username_input.text.toString(),
            email = email_input.text.toString(),
            website = website_input.text.toStringOrNull(),
            bio = bio_input.text.toStringOrNull(),
            phone = phone_input.text.toStringOrNull()
        )
    }

    override fun onPasswordConfirm(password: String) {
        if (password.isNotEmpty()) {
            val credential = EmailAuthProvider.getCredential(mUser.email, password)
            mAuth.currentUser!!.reauthenticate(credential) {
                mAuth.currentUser!!.updateEmail(mPendingUser.email) {
                    updateUser(mPendingUser)
                }
            }
        } else {
            showToast("You must enter your password")
        }
    }

    private fun updateUser(user: com.example.homeactivity.models.User) {
        val updatesMap = mutableMapOf<String, Any?>()
        if (user.name != mUser.name) updatesMap["name"] = user.name
        if (user.username != mUser.username) updatesMap["username"] = user.username
        if (user.website != mUser.website) updatesMap["website"] = user.website
        if (user.bio != mUser.bio) updatesMap["bio"] = user.bio
        if (user.email != mUser.email) updatesMap["email"] = user.email
        if (user.phone != mUser.phone) updatesMap["phone"] = user.phone

        mDatabase.updateUser(mAuth.currentUser!!.uid, updatesMap) {
            showToast("Profile saved")
            finish()
        }
    }

    private fun validate(user: com.example.homeactivity.models.User): String? =
        when {
            user.name.isEmpty() -> "Please enter name"
            user.username.isEmpty() -> "Please enter username"
            user.email.isEmpty() -> "Please enter email"
            else -> null
        }

    private fun FirebaseUser.updateEmail(email: String, onSuccess: () -> Unit) {
        updateEmail(email).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                showToast(it.exception!!.message!!)
            }
        }
    }

    private fun StorageReference.uploadUserPhoto(uid: String, photo: Uri,
                                                 onSuccess: (UploadTask.TaskSnapshot) -> Unit) {
        child("users/$uid/photo").putFile(mImageUri).addOnCompleteListener {
            if (it.isSuccessful) {
                mStorage.child("users/$uid/photo").downloadUrl.addOnCompleteListener { task ->
                    if (it.isSuccessful) {
                        onSuccess(it.result!!)
                    } else {
                        showToast(it.exception!!.message!!)
                    }
                }
            }
        }
    }


    private fun DatabaseReference.updateUserPhoto(uid: String, photoUrl: String,
                                                  onSuccess: () -> Unit){
        child("users/$uid/photo").setValue(photoUrl)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    showToast(it.exception!!.message!!)
                }
            }
    }

    private fun DatabaseReference.updateUser(
        uid: String, updates: Map<String, Any?>,
        onSuccess: () -> Unit
    ) {
        child("users").child(uid).updateChildren(updates)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    showToast(it.exception!!.message!!)
                }
            }
    }

    private fun FirebaseUser.reauthenticate(credential: AuthCredential, onSuccess: () -> Unit) {
        reauthenticate(credential).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                showToast(it.exception!!.message!!)
            }
        }
    }
}

Answer:

Change your uploadUserPhoto method like this

    private fun StorageReference.uploadUserPhoto(uid: String, photo: Uri,
                                             onSuccess: (String) -> Unit) {
    val uTask = mStorage.child("users/$uid/photo").putFile(mImageUri)
    child("users/$uid/photo").putFile(mImageUri).addOnCompleteListener {
        if (it.isSuccessful) {
            uTask.continueWithTask { task ->
                mStorage.child("users/$uid/photo").downloadUrl
            }.addOnCompleteListener{
               if (it.isSuccessful && it.result != null) {
                    onSuccess(it.result!!.toString)
                } else {
                    showToast(it.exception!!.message!!)
                }
            }
        }
    }
}

In your onActivityResult use url like

 val photoUrl = it

Question:

I am trying to upload and display the profile picture using Glide & Firebase. Upload part is successfully working. But if i try to load that image from Database its showing blank.My motive is to load the profile_image while the user entered into the activity once and he can tap on the existing image and change that for his wish.

My code

public class User extends AppCompatActivity {

    private ImageView imageView;
    private Uri filePath;
    private final int PICK_IMAGE_REQUEST = 71;
    StorageReference storageReference;

    private void loadImage(){

        Bundle bundle = getIntent().getExtras();
        assert bundle != null;
        final String retrievedName = bundle.getString("Name");

        // Reference to an image file in Cloud Storage
        StorageReference storageReference  = FirebaseStorage.getInstance().getReference().child(retrievedName).child("images/profile_image");
        imageView = findViewById(R.id.profile_image);

    // Load the image using Glide
        Glide.with(User.this.getApplicationContext())
                .load(storageReference)
                .into(imageView );
    }


    private void uploadImage() {

        if(filePath != null)
        {

            Bundle bundle = getIntent().getExtras();
            assert bundle != null;
            final String retrievedName = bundle.getString("Name");

            storageReference = FirebaseStorage.getInstance().getReference();

            StorageReference ref = storageReference.child(retrievedName).child("images/profile_image");
            ref.putFile(filePath)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            Toast.makeText(User.this, "Uploaded", Toast.LENGTH_SHORT).show();
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(User.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    });
        }
    }

    private void chooseImage() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK
                && data != null && data.getData() != null )
        {
            filePath = data.getData();
            try {
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                imageView.setImageBitmap(bitmap);

                uploadImage();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        imageView = findViewById(R.id.profile_image);

        loadImage();

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                    chooseImage();
            }
        });
    }

}

Answer:

As is told in the official firebase documentation HERE you should getDownloadURL() of your photo in order to pass it to your glide library, this way glide will show up your image

in this line add getDownloadUrl();

    StorageReference ref = storageReference.child(retrievedName).child("images/profile_image").getDownloadUrl();

and then just call your image with glide

// Load the image using Glide
Glide.with(this /* context */)
        .using(new FirebaseImageLoader())
        .load(ref)
        .into(imageView);

in order to use FirebaseImageLoader() just remember to add this in your gradle

dependencies {
    // FirebaseUI Storage only
    compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}

Also follow up THIS GitHub link on how to load an image from a StorageReference

Another easier way is getting that DownloadUrl and use it in glide

ref.putFile(filePath)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                         @SuppressWarnings("VisibleForTests") Uri downloadUrl = 
                     taskSnapshot.getDownloadUrl();
                    uploadImageUrl = downloadUrl.toString();
                Toast.makeText(getApplicationContext(), "url to your file..."+uploadImageUrl, Toast.LENGTH_SHORT).show();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(User.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

uploadImageUrl is a global variable private String uploadImageUrl;

And then just load that image url with glide into your imageView

Glide.with(this /* your_context */)
    .load(uploadImageUrl)
    .centerCrop()
    .into(imageView)

Question:

Searched many sites and I haven't yet found the answer.

The image isn't being uploaded from Firebase and I honestly don't know what it could be.

Thanks in advance.

Code:

spaceRef = storageRef.child("Users/" + user.getEmail().toString() + "/images/Countries/Spain" /*+ chosenCountry*/);

            Glide.with(ActPhotoViewing.this.getApplicationContext())
                    .load(spaceRef)
                    .into(showImg);

Implementations in .gradle

implementation 'com.firebaseui:firebase-ui-storage:3.2.1'
implementation 'com.github.bumptech.glide:glide:4.4.0'

Answer:

When using FirebaseUI you need to use the generated API. When you build your project it should generate a GlideApp class that you will use in place of your Glide static calls.

Try:

    GlideApp.with(ActPhotoViewing.this.getApplicationContext())
            .load(spaceRef)
            .into(showImg);

If you are getting errors that GlideApp is not found make sure you are following the instructions here https://github.com/firebase/FirebaseUI-Android/tree/master/storage. Then clean/rebuild your project.

Question:

Well im using firebase to store images related to the user profile, and something really weid is happening currently, i have a default image in my drawables that is displayed in a imageview that i have everytime my firebase storage ref is empty, else it will use glide to display the image, but i deleted all my storage at firebase and it stil show a image that i had in the database, why is that happening? is that related to the localStorage on the phone? how can i delete it?

    storageRef = storage.getReferenceFromUrl("gs://friendlymanager-3b7a2.appspot.com/Photos/" + userId);


Uri path = Uri.parse("android.resource://com.esmad.pdm.friendlymanager/" + R.drawable.defaultuserimage);
Log.d("image2",storageRef + "/Photos/" + userId + ".jpg");
if(storageRef != null){
    Glide.with(this)
            .using(new FirebaseImageLoader())
            .load(storageRef)
            .error(R.drawable.defaultuserimage)
            .into(userImage);
}
else{
    userImage.setBackgroundResource(R.drawable.defaultuserimage);
}

Answer:

Try disabling use of both the disk and memory caches:

    Glide.with(this)
            .using(new FirebaseImageLoader())
            .load(storageRef)
            .diskCacheStrategy(DiskCacheStrategy.NONE) // <= ADDED
            .skipMemoryCache(true) // <= ADDED
            .error(R.drawable.defaultuserimage)
            .into(userImage);

Added:

Testing storageRef for null cannot be used to determine if data is stored at that location. You can only determine the presence of data at a location by trying to load either the data or its metadata.