问题描述
我正在尝试通过使用Compressor库创建两个文件夹来将图像上传到实时Firebase数据库,并且需要显示带有用户名的Messenger等图像,但是由于网址问题,我无法显示图像
I am trying to upload images to Real time Firebase Database by creating two folders using Compressor library and need to display image like messenger with username but i am unable to display image due to url issue
var filePath = mStorageRef!!.child("chat_profile_images")
.child(userId + ".jpg")
//Create another directory for thumbimages ( smaller, compressed images)
var thumbFilePath = mStorageRef!!.child("chat_profile_images")
.child("thumbs")
.child(userId + ".jpg")
filePath.putFile(resultUri)
.addOnCompleteListener{
task: Task<UploadTask.TaskSnapshot> ->
if (task.isSuccessful) {
//Let's get the pic url
var donwloadUrl = task.result?.storage?.downloadUrl.toString()
Log.d(TAG, "Profilepic link: $donwloadUrl")
//Upload Task
var uploadTask: UploadTask = thumbFilePath
.putBytes(thumbByteArray)
uploadTask.addOnCompleteListener{
task: Task<UploadTask.TaskSnapshot> ->
var thumbUrl = task.getResult()?.storage?.downloadUrl.toString()
Log.d(TAG, "Profilepic link: $thumbUrl")
我试图更改downloadUrl
i tried to change downloadUrl
filepath.downloadUrl.toString
thumbFilePath.downloadUrl.toString
但是这两个值都变为"com.google.android.gms.tasks.zzu"
but both these values getting "com.google.android.gms.tasks.zzu"
我也尝试更改
task.result.sessionurl.downloadUrl.toString
为此,我正在获取downloadUrl,但无法解决我的问题,因为仍然无法显示图像,我需要获取thumbUrl downloadUrl
for this one i am getting downloadUrl but not a complete solution for my problem as still i cannot display image i need to get thumbUrl downloadUrl
推荐答案
与,除了它在Java中.您应该按照此处的文档以了解获取 getDownloadUrl 可行.从链接的API文档中可以看到,它不是属性获取器,它实际上是一个返回Task<Uri>
的方法,该方法可以跟踪所需的URL的异步提取,就像上载任务一样:
You have the exact same and very common misunderstanding as in this question, except it's in java. You should follow the documentation here to understand get getDownloadUrl works. As you can see from the linked API documentation, it's not a property getter, it's actually a method that returns a Task<Uri>
that tracks the asynchronous fetch of the URL you want, just like the upload task:
filePath.downloadUrl
.addOnSuccessListener { urlTask ->
// download URL is available here
val url = urlTask.result.toString()
}.addOnFailureListener { e ->
// Handle any errors
}
这仅在完全完成上传后才能起作用.
This will only work after the upload is fully complete.
这篇关于Kotlin-获取Firebase图像DownloadUrl返回"com.google.android.gms.tasks.zzu"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!