gpt4 book ai didi

swift - 元数据?.downloadURL()?.absoluteString

转载 作者:行者123 更新时间:2023-11-30 11:28:02 24 4
gpt4 key购买 nike

我对旧语法有一些问题,例如:

metadata?.downloadURL()?.absoluteString"

如何在我的代码中使用新方法?这部分代码错误:

let downloadURL = metadata?.storageReference?.downloadURLWithCompletion()

完整代码:

Storage.storage().reference().child(imgUid).putData(imgData, metadata: metadata) { (metadata, error) in
if error != nil {
print("Did'n upload image")
} else {
print("uploaded")
let downloadURL = metadata?.storageReference?.downloadURLWithCompletion()

if let url = downloadURL {
self.setUser(img: url)
}
}
}

最佳答案

这是一种简单的方法,使用此 Func 将数据保存到 FirebaseStorage,然后将 url 作为字符串,然后将其保存在

func uploadImageToFirebaseStorage(data: Data, onSuccess: @escaping (_ imageUrl: String) -> Void) {
let photoIdString = NSUUID().uuidString
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_REF_URL).child(POST_REF).child(photoIdString)


storageRef.putData(data, metadata: nil) { (metadata, error) in
if let error = error {
debugPrint(error.localizedDescription)
return
}

metadata?.storageReference?.downloadURL(completion: { (url, error) in
if let error = error {
print(error.localizedDescription)
return
}
onSuccess("\(url!)")
})
}
}

关于swift - 元数据?.downloadURL()?.absoluteString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50536560/

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