ios - 如何将配置文件链接上传到 Firebase 数据库
问题描述
当我的“ ProfileImageuUrl ”出现在firebase数据库中时,配置文件图像的链接丢失,这导致我的用户配置文件失火,图像不会显示,因为firebase数据库中没有链接我该如何重组我的代码到这个问题
if let AuthData = AuthDataResult {
print(AuthData.user.email)
let dict : Dictionary < String, Any> = [
"uid": AuthData.user.uid,
"email": AuthData.user.email,
"ProfileImageUrl": "",
]
if let profileImge = self.selectedImage, let imageData = profileImge.jpegData(compressionQuality: 0.1) {
let StorageRef = Storage.storage()
.reference(forURL: "gs://tunnel-vision-458d6.appspot.com/")
let storageProfileRef = StorageRef.child("profileImage").child(AuthData.user.uid)
let metadata = StorageMetadata()
metadata.contentType = "profileImage.jpg"
storageProfileRef.putData(imageData, metadata: metadata) { (storageMetadata, error) in
if error != nil {
return
}
storageProfileRef.downloadURL { (url, error) in
if let metaImageUrl = url?.absoluteString {
print(metaImageUrl)
}
Database.database().reference().child("users").child(AuthData.user.uid).updateChildValues(dict, withCompletionBlock: {
(error,ref) in
if error == nil {
print("Done")
}
解决方案
You are assigning an empty string for ProfileImageUrl in dict:
let dict : Dictionary < String, Any> = [
"uid": AuthData.user.uid,
"email": AuthData.user.email,
"ProfileImageUrl": "",
]
And you never update it afterward. The dict is written exactly as you see it here. Assign it the value you want before writing it.
推荐阅读
- python - 如何为数据框中的多列剪辑熊猫
- reactjs - React:状态更新后组件未重新渲染
- r - 在 Rstudio 中更改源代码,但代码是用 C 编写的
- python - 如何使用python将图像插入特定的excel文件单元格?
- python - Tensorflow,GPU 比 CPU 快多少?(余弦相似度计算)
- java - 在 dp android 中设置文本大小后,文本在我的自定义视图中的不同屏幕上被拉伸
- javascript - Javascript 对象数组的控制台输出差异
- wxmaxima - Wxmaxima 中的线不够高,无法显示指数的指数 [已解决]
- sql-server - SQL Server 2016,游标
- openshift - Openshift 4.6 节点和主配置文件