【问题标题】:Updating user profile photo does not update it with currentUser.photoUrl更新用户个人资料照片不会使用 currentUser.photoUrl 更新它
【发布时间】:2020-07-09 12:28:22
【问题描述】:

我已经拍了一张照片,然后我更新了我当前的用户照片以将此更改应用到经过 Firebase 身份验证的用户。

我希望在将这张照片更新给经过身份验证的用户之后,将 photoUrl 作为字符串获取,就像我第一次登录我的应用程序时一样

suspend fun updatePhoto(uri: Uri): Resource<Unit>{
        val currentUser = FirebaseAuth.getInstance().currentUser
        val profileUpdates = UserProfileChangeRequest.Builder().setPhotoUri(uri).build()
        currentUser!!.updateProfile(profileUpdates).await()
        currentUser.reload().await()
        val userData = hashMapOf<String,Any>()
        userData["photoUrl"] = currentUser.photoUrl.toString()
        FirebaseFirestore
            .getInstance()
            .collection("user")
            .document(currentUser.uid).set(userData, SetOptions.merge()).await()
        return Resource.Success(Unit)
    }

在这一行 userData["photoUrl"] = currentUser.photoUrl.toString() 我希望实际的 photoUrl 在 firebase 中更新,并且我得到了一个本地 Uri,例如 file://my.com.app/cache/photo.jpg

如果我从身份验证本身更新了用户照片,firebase 不会处理更新后的照片,需要返回当前用户更新的实际照片吗?

我想避免使用 firebase 存储来上传照片并将其放在我的数据库中,而是直接从更新的用户照片中检索它

【问题讨论】:

    标签: android firebase kotlin google-cloud-firestore firebase-authentication


    【解决方案1】:

    当您设置 Firebase 身份验证用户照片网址时,它不会获取该图像的内容并将其存储。您可能从应用程序的另一部分传递了该文件 URL,现在它返回了相同的字符串,正如预期的那样。

    我认为没有任何方法可以避免将该图像上传到可以为您托管它的服务,例如 Cloud Storage。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 2017-09-12
      • 2011-02-14
      • 1970-01-01
      相关资源
      最近更新 更多