bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.61k stars 6.12k forks source link

how to load a ipfs url? #5408

Open yuzhongrong opened 4 months ago

yuzhongrong commented 4 months ago

i have a ipfs url link: https://bafkreibrvtwbbiyynjtgedbw6keddxfhmmfvqaawyrfylhalhjtfuuvore.ipfs.nftstorage.link

my code for android:

@GlideModule public class IPFSAppGlideModule extends AppGlideModule { @Override public void applyOptions(Context context, GlideBuilder builder) { }

@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
    Log.e("IPFSAppGlideModule","----->registerComponents");
    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {

                    Request original = chain.request();
                    Request request = original.newBuilder()
                            .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
                            .build();
                    return chain.proceed(request);

                }
            })
            .followRedirects(true)
            .followSslRedirects(true)
            .build();

    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));

}

}

log: W/Glide: Load failed for https://bafkreibrvtwbbiyynjtgedbw6keddxfhmmfvqaawyrfylhalhjtfuuvore.ipfs.nftstorage.link with size [135x135] class com.bumptech.glide.load.engine.GlideException: Failed to load resource There was 1 root cause: com.bumptech.glide.load.HttpException(, status code: 403) 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 root cause: com.bumptech.glide.load.HttpException(, status code: 403) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed There was 1 root cause: com.bumptech.glide.load.HttpException(, status code: 403) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class com.bumptech.glide.load.HttpException: , status code: 403 I/Glide: Root cause (1 of 1) com.bumptech.glide.load.HttpException: , status code: 403 at com.bumptech.glide.integration.okhttp3.OkHttpStreamFetcher.onResponse(OkHttpStreamFetcher.java:71) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:930)