gpt4 book ai didi

ios - 如何根据用户id存储上传的图片

转载 作者:行者123 更新时间:2023-11-30 10:58:45 26 4
gpt4 key购买 nike

func uploadImage(){

let storage = Storage.storage()
let storageRef = storage.reference()
let uploadData = self.imageView.image!.jpegData(compressionQuality: 0.75)
let imagesRef = storageRef.child("images/myImage.jpg") //not sure how is it done
let uploadTask = imagesRef.putData(uploadData!, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
return
}

let size = metadata.size

imagesRef.downloadURL { (url, error) in
guard let downloadURL = url else {
return
}
}
}
}


func retrieveData(){

let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in

let userData = snapshot.value as? NSDictionary
print("Welcome back,", userData?["username"])

}) { (error) in
print(error.localizedDescription)
}
}

嗨,我正在寻找一种让用户根据用户 ID 将图像上传到 Firebase 的方法。谁能建议如何实现这一目标?提前致谢。

最佳答案

你可以这样做:

func sendMessageWithProperties(properties: [String: Any]) {
let ref = Database.database().reference().child("messages")
let childRef = ref.childByAutoId()

let toId = self.user?.id
let fromId = Auth.auth().currentUser?.uid
let timestamp: Int = Int(NSDate().timeIntervalSince1970)
var values: [String: Any] = ["toId": toId!,
"fromId": fromId!,
"timestamp": timestamp]

// To append other properties into values
properties.forEach({values[$0] = $1})

childRef.updateChildValues(values) { (error, ref) in
if error != nil {
print(error!)
return
}

let userMessageRef = Database.database().reference().child("user-messages").child(fromId!).child(toId!)
let messageId = childRef.key
userMessageRef.updateChildValues([messageId: 1])

let receiverMessageRef = Database.database().reference().child("user-messages").child(toId!).child(fromId!)
receiverMessageRef.updateChildValues([messageId: 1])
}
}

关于ios - 如何根据用户id存储上传的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53646481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com