Can't load image by placeholder.com url

got a strange problem, trying to download any photo by url inside model from here -> https://jsonplaceholder.typicode.com/photos, for example this "https://via.placeholder.com/150/92c952" but getting error:

Glide: Load failed for https://via.placeholder.com/600/92c952 with size [788x788]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
 call GlideException#logRootCauses(String) for more detail
  Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
 call GlideException#logRootCauses(String) for more detail
    Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
 call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class java.io.FileNotFoundException: https://via.placeholder.com/600/92c952

btw if I'm trying to load images from other links, for example this -> https://avatars.mds.yandex.net/get-pdb/1088712/8b19d278-0b9b-46f8-89e4-66f5541efc55/s1200?webp=false

everything is working fine. Also I would like to mention that image isn't loading with Picasso, Fresco and etc. Using

InputStream inputStream = new URL(urlLik).openStream();
bitmap = BitmapFactory.decodeStream(inputStream);

doesn't help neither.
Thanks in advance, really stack at this prob.

Code with loading image using glide:

 RequestOptions requestOptions = RequestOption.placeholderOf(R.drawable.white_background).timeout(15000)
                    .error(R.color.grey);
        Glide.with(application)
                    .setDefaultRequestOptions(requestOptions).load("https://via.placeholder.com/150/92c952")
.placeholder(R.drawable.white_background).dontAnimate().into(image);

Upvotes: 4

Views: 7872

Answers (2)

Amee Joshi
Amee Joshi

Reputation: 11

Use coil library for image loading. Add the following dependecny in your app level build.gradle :

implementation("io.coil-kt:coil:0.9.1")

To load from an URL:

imageView.load("https://via.placeholder.com/600/92c952")

Upvotes: 1

Maddy Blacklisted
Maddy Blacklisted

Reputation: 1190

This issue is related to User-Agent header parameter. It's not related to Glide, it's all about https://via.placeholder.com. You can workaround this by creating the URL by GlideUrl and adding User-Agent header.

GlideUrl url = new GlideUrl("https://your-url.com", new LazyHeaders.Builder()
            .addHeader("User-Agent", "your-user-agent")
            .build());

Upvotes: 13

Related Questions