Glide无法加载服务器映像网址

时间:2017-07-18 03:07:39

标签: android kotlin android-glide

尝试加载类似此网址的图片

"https://firebasestorage.googleapis.com/v0/b/content-office-e1931.appspot.com/o/usersData%2Fposts%2Fmedia_-KpGAURJbB33BKhTynV1?alt=media&token=26135949-a918-4572-9293-b639d43f04aa"

但滑行显示日志

Load failed for  with size [360x360]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
class com.bumptech.glide.load.engine.GlideException: Failed to load resource

以前的日志

Failed to find GeneratedAppGlideModule. You should include an annotationProcessor 
compile dependency on com.github.bumptech.glide:glide:compiler in your application 
and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules 
will be silently ignored

我无法理解为什么我要添加AppGlideModule等只是为了加载图片。我在Kotlin中的代码,我添加了编译器依赖,如下所示

 //image loader
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
kapt 'com.github.bumptech.glide:compiler:4.0.0-RC1'

以下是我如何称之为Glide

 fun bind(post: Post) {
    for ((k, v) in post.media) {
        Glide.with(itemView.context)
                .asBitmap()
                .apply(RequestOptions.encodeQualityOf(70))
                .apply(RequestOptions.overrideOf(width,width))
                .apply(RequestOptions.centerCropTransform())
                .load(v.downloadPath)
                .into(image)
    }
}

我曾尝试附加一个监听器来查看日志,当Glide尝试加载图像时发生了什么,但我只看到“无法加载资源”没什么用处

5 个答案:

答案 0 :(得分:0)

它与我合作:

Glide.with(itemView.context)
  .load(new URL(v.downloadPath))
  .into(image);

答案 1 :(得分:0)

您的图片来源网址不正确,请使用浏览器检查它的来源,以确保其正确。

答案 2 :(得分:0)

我不知道此解决方案对每个人都适用,但就我而言,它可行!

<application
    android:usesCleartextTraffic="true"


</application>

并尝试以这种格式加载图像

Glide.with(context)
.load(new URL(your_image))
.into(image)

答案 3 :(得分:0)

您的 URL开头和结尾不应包含空格,即使它们有可能修饰您的网址。

答案 4 :(得分:0)

只需使用此策略即可完成。

Glide.with(context)
            .asBitmap()
            .load("Your Network Image Path")
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(new CustomTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    iv.setImageBitmap(resource);
                    iv.buildDrawingCache();
                }
                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) { }
            });