我猜Kotlin对downloadURI方法进行了一些更改。我正在尝试使用如下所示的新版本,
private fun uploadPhotoToFirebase(result: ByteArray?) {
var storageRef = FirebaseStorage.getInstance().getReference()
val ref = storageRef.child("uploads/profil.jpg")
var uploadTask = ref.putBytes(result!!)
uploadTask.continueWithTask { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
ref.downloadUrl
}
uploadTask.addOnCompleteListener { task ->
if (task.isSuccessful) {
val downloadUri = task.result
//var test = downloadUri.toString()
//Log.e("TEST", downloadUri.toString())
FirebaseDatabase.getInstance().reference
.child("users")
.child("username")
.setValue(aa)
} else {
// Handle failures
// ...
}
}
}
当我使用上面的代码时,它成功上传了照片,但是下面出现了错误,
Process: com.example.testapp, PID: 22169
com.google.firebase.database.DatabaseException: Serializing Collections is not supported, please use Lists instead
如果我按如下所示更改downloadUri行,这一次我可以成功写入数据库,但是我得到的是“ gs://testapp.appspot.com/uploads/profil.jpg”链接,但这没用。 / p>
val downloadUri = task.result?.storage.toString()
如何获取照片URL并将其写入Firebase DB?
谢谢。