0

I'm trying to display the image in CircularImageView stored in Firebase Storage, but glide gives me this error:

W/Glide: Load failed for gs://project-2d8i4.appspot.com/pictures/3HnfQSeBladDsD9sPEcKrhxJ6CB2 with size [1200x1200]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource

The picture is saved in Firestore as:

"gs://project-2d8i4.appspot.com/pictures/3HnfQSeBladDsD9sPEcKrhxJ6CB2"

Binding to image view (uri = "gs://project-2d8i4.appspot.com/pictures/3HnfQSeBladDsD9sPEcKrhxJ6CB2"):

fun CircularImageView.bindProfilePicture(uri: String?) {
    Glide
        .with(this)
        .load(uri)
        .into(this)
}

Dependencies for glide:

implementation 'com.github.bumptech.glide:glide:4.12.0'

No answers in any posts helped me whatsoever. I hope someone could help me. Thanks.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Captain Jacky
  • 888
  • 1
  • 12
  • 26

2 Answers2

2

The following URL:

gs://project-2d8i4.appspot.com/pictures/3HnfQSeBladDsD9sPEcKrhxJ6CB

Is indeed a file that is stored in Cloud Storage. Unfortunately, this URL is not recognized by Glide, as it is not a valid URL. To solve the problem you need to get the "download URL" rather than an URL that starts with gs://....

To get the actual download URL, please see the official documentation for:

And my answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Hi, thanks. Whenever I upload the picture even with the same ID to the storage, downloadUrl changes all the time, which is great. It helps me with the real-time solutions. – Captain Jacky Feb 28 '21 at 11:51
1

To avoid cache as mentioned in comments, you can use these two along with glide call.

diskCacheStrategy(DiskCacheStrategy.NONE) 
.skipMemoryCache(true)

Check here to use the glide to download from firebase url.

Android Killer
  • 18,174
  • 13
  • 67
  • 90
  • Do I need to download that file to local storage? Because I receive the same error and additionally `java.io.IOException(File unsuitable for memory mapping)`. If looking at Firebase documentation, when using FirebaseUI I simply need to pass the reference to that file - it's what I did. – Captain Jacky Feb 28 '21 at 09:11
  • 1
    My bad, if you can check here : https://medium.com/@egemenhamutcu/displaying-images-from-firebase-storage-using-glide-for-kotlin-projects-3e4950f6c103 – Android Killer Feb 28 '21 at 09:35
  • Great. It does get load, but when I update my storage with different pic using same ID, and then GlideApp gets that picture under that ID, it always returns first picture that I uploaded. How is this possible? Is this getting cached on my phone or what? – Captain Jacky Feb 28 '21 at 10:39
  • Use these two methods along with your above glide code. .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) – Android Killer Feb 28 '21 at 11:40
  • Is it a good idea to use those two? Actually, by using Alex's answer I can use catching and also the downloadUrl changes all the time whenever I change storage's pic even with the same ID. Thanks for the help. – Captain Jacky Feb 28 '21 at 11:49