48

I am trying to load an image into imageView through Glide. But the image is not loaded - I get an error. I'm using the following code

GlideApp.with(context) .load(itemData.getThumbnailUri()) .placeholder(R.mipmap.koya_logo_white) .error(R.mipmap.ic_image_loading_error) .into(itemBinding.cover); 

Logs

lide: Load failed for https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png with size [1080x1080] 
class com.bumptech.glide.load.engine.GlideException: Failed to load resource Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{StringUri->Object->Drawable}, LOCAL, DataCacheKey{sourceKey=https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png, signature=EmptySignature} Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Drawable->Drawable} Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Bitmap->Drawable} 
7
  • whats glide version you are using ? Commented Apr 2, 2019 at 11:01
  • I'm using Glide version 4.8.0 Commented Apr 2, 2019 at 11:06
  • Try printing the value of itemData.getThumbnailUri() in logs and check if its valid URI format or not Commented Apr 2, 2019 at 11:12
  • 1
    Could you find a solution to your issue? I have the same problem for two/three days. Commented May 5, 2019 at 9:43
  • Hey! What solution?? I have the same issue on android 22 api and below - cant load url like screen of camera 4mp, ex: fs05.naveksoft.com:62121/a109b1b0-4f05-45f2-9e55-35d672d13038/… Commented Sep 13, 2019 at 13:19

18 Answers 18

7

Another reason why this problem appears is the phone/emulator doesn't have an internet connection.

Sign up to request clarification or add additional context in comments.

1 Comment

If it still didn't worked, try uninstall and re-install the app. Hope it works!
6

The solution works for me:
1. Update build.gradle(Module: app)

 implementation "com.github.bumptech.glide:glide:4.7.1" kapt "com.github.bumptech.glide:compiler:4.7.1" implementation "com.squareup.okhttp3:okhttp:3.14.0" implementation ('com.github.bumptech.glide:okhttp3-integration:4.7.1'){ exclude group: 'glide-parent' } 
  1. Set timeout for glide

     @GlideModule class MyAppGlideModule : AppGlideModule() { override fun registerComponents(context: Context, glide: Glide, registry: Registry) { val client = OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .build() val factory = OkHttpUrlLoader.Factory(client) glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory) } } 

Comments

6

Simplest solution

add,

android:usesCleartextTraffic="true" 

inside your <application/> tag of AndroidManifest.xml file.

2 Comments

@IlyaGazman exactly, The default value target API level 27 or lower is "true". Apps that target API level 28 or higher default to "false"
it worked for me! you don't need this when using api level 8 downwards but when working on api 8.1 and above you will need this particular solution
6

Try this solution...

String url = "https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png"; GlideApp.with(context).load(url) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .error(R.drawable.glide_app_img_loader) .listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { return false; } }).into(imageView); 

3 Comments

class com.bumptech.glide.load.engine.GlideException: Failed to load resource There were 2 causes: com.bumptech.glide.load.HttpException(Forbidden) com.bumptech.glide.load.HttpException(Forbidden) call GlideException#logRootCauses(String) for more detail Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
are you sure you are using only HTTPS urls ?
I'm not using url, but internal storage and the override with target sizes did the trick! Thanks!
2

Update the Glide version to :

 implementation 'com.github.bumptech.glide:glide:4.14.2' annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2' 

Comments

1

Am also faced this issue.Its bug from glide side.Use the latest version of glide.

repositories { mavenCentral() google() } dependencies { implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' } 

Make sure that itemData.getThumbnailUri() not contain empty space

Comments

1

I also had this problem. When I wrote the layout like this

<FrameLayout android:layout_width="@dimen/view_width" android:layout_height="@dimen/view_height"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"/> </FrameLayout> 

and I changed that to

<FrameLayout android:layout_width="@dimen/view_width" android:layout_height="@dimen/view_height"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout> 

This solution worked for me.

Comments

1

for me the url was " https//app.domain.." the issue here is the space at the beginning of the url

Comments

0

Same with @ievgen answers.

  • Check for your internet connection
  • HTTPS connection issue for Android 8 or 9, see here
  • The issue might occur due to invalid URL or having a trailing space or / slash

My project was getting an API from TMDB, and using val BASE_IMAGE = http://image.tmdb.org/t/p/w780/ notice the last trailing w780/ "slash"?

It is concatenated mistakenly e.g:

W/Glide: Load failed for http://image.tmdb.org/t/p/w780//qJdfO3ahgAMf2rcmhoqngjBBZW1.jpg with size [-2147483648x-2147483648]

Removing the trailing / slash fixed my issue. E.g from:

http://image.tmdb.org/t/p/w780/ -> http://image.tmdb.org/t/p/w780 

Here's my setup:

Glide: 4.9.0 Android Studio: 3.4.1 (Grale Build Tools) 

Comments

0

Create image decoder like this:

class PageDecoder( private val bitmapPool: BitmapPool ) : ResourceDecoder<InputStream, Bitmap> { companion object { val PAGE_DECODER: Option<Boolean> = Option.memory("abc") } override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<Bitmap>? { return BitmapResource.obtain(BitmapFactory.decodeStream(source), bitmapPool) } override fun handles(source: InputStream, options: Options): Boolean = options.get(PAGE_DECODER) ?: false } 

In your glide module should apply this:

override fun registerComponents(context: Context, glide: Glide, registry: Registry) { registry.prepend(InputStream::class.java, Bitmap::class.java, PageDecoder(glide.bitmapPool)) } 

In activity there you load image use this:

GlideApp.with(context) .load("Image url or path, etc") .apply(GlideOptions.option(PageDecoder.PAGE_DECODER, true)) .into(imageview) 

It's work for me, I hope it's was helpfull for you.

Comments

0
Glide.with(this) .load(imageItem.img_url.toUri().buildUpon().scheme("https").build()) .into(mars_image) 

Try to extend your url with load(imageItem.img_url.toUri().buildUpon().scheme("https").build()) this extension for https.

Comments

0

I had the same issue and this is what worked for me. Replacing the http to https.

 if (url.startsWith("https")) { Glide.with(imageView.getContext()) .load(url) .error(R.drawable.thumblin) .fitCenter() .into(imageView); } else { Glide.with(imageView.getContext()) .load(url.replace("http","https")) .error(R.drawable.thumblin) .fitCenter() .into(imageView); } 

Comments

-1

Check if the Uri you are passing is correct ,for me it was bug in the Uri being passed as I was Appending the required BaseUri twice

Comments

-1

This worked for me in Kotlin

 Glide.with(context).load(url) .override(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL).listener( object : RequestListener<Drawable> { override fun onLoadFailed( e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean ): Boolean { return false } override fun onResourceReady( resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean ): Boolean { return false } } ).into(imageView) 

1 Comment

Please add further details to expand on your answer, such as working code or documentation citations.
-1

I was having same problem with Glide + AndroidSVG as some Vector images were not loaded and having to check between SVG and PNG for Glide to process correctly.

here is the alternate solution presented by @sadegh . Please go ahead to direct answer.

ALTERNATIVE WAY : kotlin + Coil

This solution will work well with .svg , .png , .jpg

add dependency:

//Coil (https://github.com/coil-kt/coil) implementation("io.coil-kt:coil:1.4.0") implementation("io.coil-kt:coil-svg:1.4.0") 

add this function to your code:

fun ImageView.loadUrl(url: String) { val imageLoader = ImageLoader.Builder(this.context) .componentRegistry { add(SvgDecoder([email protected])) } .build() val request = ImageRequest.Builder(this.context) .crossfade(true) .crossfade(500) .placeholder(R.drawable.placeholder) .error(R.drawable.error) .data(url) .target(this) .build() imageLoader.enqueue(request) } 

Then call this method in your activity or fragment:

 imageView.loadUrl(url) // url example : https://upload.wikimedia.org/wikipedia/commons/3/36/Red_jungle_fowl_white_background.png 

Comments

-2

Try to uninstall your app from emulator and try compile again. It's working for me.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-5

As we use the AWS and with my experience to it found that Glide is not able to load HTTP URLs but works fine if we use HTTPS over the HTTP.

Also, it fails to loads large images for say resolution 1800x1800 or more.

Why? It fails to load that much data of an image on some specific device due to less heap. So the best option is to use RequestOptions and apply it to the Glide.

try { String url = "" /* URL of Image */; if (url.startsWith("http://")) url = url.replace("http://", "https://"); RequestOptions requestOptions = new RequestOptions(); requestOptions.placeholder(R.mipmap.app_icon); requestOptions.error(R.mipmap.app_icon); Glide .with(context) .setDefaultRequestOptions(requestOptions) .load(url) .into(imgView); } catch (Exception e) { e.printStackTrace(); } 

Comments

-7

I think you did not add permission for your app to access the Internet.

Add this into your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.