Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在从firebase存储加载图像,而不是使用glide和Kotlin加载图像_Kotlin_Firebase Storage_Android Glide - Fatal编程技术网

正在从firebase存储加载图像,而不是使用glide和Kotlin加载图像

正在从firebase存储加载图像,而不是使用glide和Kotlin加载图像,kotlin,firebase-storage,android-glide,Kotlin,Firebase Storage,Android Glide,我正在尝试使用Kotlin和Glide从Firebase存储加载图像。我添加了所有依赖项并应用插件: implementation 'com.firebaseui:firebase-ui-storage:6.2.0' implementation 'com.google.firebase:firebase-storage-ktx:19.1.1' implementation 'com.github.bumptech.glide:glide:4.8.0' kapt 'com.github.bump

我正在尝试使用Kotlin和Glide从Firebase存储加载图像。我添加了所有依赖项并应用插件:

implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'

apply plugin: 'kotlin-kapt'
我的代码如下:

val storageRef = Firebase.storage.reference

    val imageref = storageRef.child("test/test.jpg")

    imagetest = findViewById(R.id.imageView5)

    Glide.with(this)
        .load(imageref)
        .into(imagetest)
运行代码时,具有默认图像的imageview变为黑色,表示代码正在尝试从Firebase存储检索某些内容。但是imageView从不填充下载的图像。假设下载确实发生了

我做错什么了吗?我的firebase存储屏幕截图如下:

我对此进行了更多的测试,Glide似乎可以从HTTPS加载图像,不管我从哪里获取URL。但云存储提供的URL为GS://。那么如何将GS://转换为HTTPS://呢

请帮忙。

我想出来了

imageref = Firebase.storage.reference.child("test/test.jpg")
    imageref.downloadUrl.addOnSuccessListener {Uri->

        val imageURL = Uri.toString()
        imagetest = findViewById(R.id.imageView5)


        Glide.with(this)
            .load(imageURL)
            .into(imagetest)

    }

“downloadurl”语句实际上将GS://转换为HTTPS://

这两者之间的差异:

GS网址:

HTPPS网址:


这是我解决问题的过程-

步骤1-转到build.gradleapp并添加这些依赖项

实现'com.firebaseui:firebaseui存储:4.3.2' 实现'com.github.bumptech.glide:glide:4.x.x' annotationProcessor'com.github.bumptech.glide:compiler:4.x.x' 步骤2- 创建一个java文件

@滑动模块 公共类MyAppGlideModule扩展了AppGlideModule{ @凌驾 public void register组件上下文上下文、Glide Glide、注册表{ registry.appendStorageReference.class、InputStream.class、, 新FirebaseImageLoader.工厂; } } 第3步-将图像设置在所需位置

FirebaseStorage=FirebaseStorage.getInstance; StorageReference storageRef=storage.getReferenceFromUrlgs:///.childfolder; //如果出现嵌套文件夹,则添加.childnested\u文件夹 GlideApp.withcontext .loadstorageRef.childtest_image.jpg .intocholder.缩略图; //该.load将类似于.loadgs://
gs://<your_project_id>.appspot.com/test/test.jpg
https://firebasestorage.googleapis.com/v0/b/<your_project_id>.appspot.com/o/test%2Ftest.jpg