Android Glide:加载 Firebase 存储资源失败

Android Glide: Failed to load resource of Firebase Storage

我试图在存储在 Firebase 存储中的 CircularImageView 中显示图像,但 glide 给我这个错误:

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

图片在 Firestore 中保存为:

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

绑定到图像视图(uri = "gs://project-2d8i4.appspot.com/pictures/3HnfQSeBladDsD9sPEcKrhxJ6CB2"):

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

滑翔的依赖项:

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

任何帖子中的答案都没有帮助我。我希望有人能帮助我。谢谢。

为了避免评论中提到的缓存,您可以将这两个与滑行调用一起使用。

diskCacheStrategy(DiskCacheStrategy.NONE) 
.skipMemoryCache(true)

勾选 here 使用 glide 从 firebase 下载 url。

以下URL:

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

确实是存储在云存储中的文件。不幸的是,这个 URL 不能被 Glide 识别,因为它不是一个有效的 URL。要解决此问题,您需要获取“下载 URL”而不是以 gs://....

开头的 URL

获取实际下载URL,请查看官方文档:

我的回答来自以下post:

  • How to get the download url from Firebase Storage?