下载网址以com.google.android.gms.tasks.zzu@441942b开头:Firebase存储[Kotlin]

问题描述 投票:0回答:2

我已经检查了可用资源,但是我得到了错误或者充其量还是得到了com.google.android.gms.tasks.zzu@5f9a842作为uri

遵循此最新的google文档here,我仍然收到com.gms作为网址

这是我的代码

            val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg")

            val uploadTask = fileRef.putFile(imageUri!!)
            uploadTask.continueWith {
                if (!it.isSuccessful) {
                    pd.dismiss()
                    it.exception?.let { t ->
                        throw t
                    }
                }
                fileRef.downloadUrl
            }.addOnCompleteListener {
                if (it.isSuccessful) {
                    val downloadUrl = it.result
                    myUri = downloadUrl.toString()

                    print("Task: ${downloadUrl}")
                    ...

Terminal: I/System.out: Task: com.google.android.gms.tasks.zzu@4298dc1(HTTPLog)-Static: isSBSettingEnabled false

请给我任何帮助,...

android firebase kotlin firebase-storage
2个回答
0
投票

您输入了错误的值。代替这个:

print("Task: ${downloadUrl}")

登录此:

print("Task: ${downloadUrl.result.toString()}")

您的downloadUrl变量未正确命名。这是一个任务,而不是URL。这样可能更清晰:

val task = it.result
val uri = task.result
val uriAsString = uri.toString()

0
投票

已解决!!

        val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg")

        val uploadTask = fileRef.putFile(imageUri!!)
        uploadTask.continueWith {
            if (!it.isSuccessful) {
                pd.dismiss()
                it.exception?.let { t ->
                    throw t
                }
            }
            fileRef.downloadUrl
        }.addOnCompleteListener {
            if (it.isSuccessful) {
                val downloadUrl = it.result //Here returns a task..
                myUri = downloadUrl.toString()

                print("Task: ${downloadUrl}")
                ...

[val downloadurl = it.result返回一个Task

通过添加addOnSuccessListener进行更正

所以正确的代码是

val uploadTask = fileRef.putFile(imageUri!!)
        uploadTask.continueWith {
            if (!it.isSuccessful) {
                pd.dismiss()
                it.exception?.let { t ->
                    throw t
                }
            }
            fileRef.downloadUrl
        }.addOnCompleteListener {
            if (it.isSuccessful) {
                it.result!!.addOnSuccessListener{task ->
                                 myUri = task.toString()
                                print("$myUri")
                                 ...
                                    }
© www.soinside.com 2019 - 2024. All rights reserved.