gpt4 book ai didi

swift - 类型 'StorageMetadata' 的值没有成员 'downloadURL'

转载 作者:行者123 更新时间:2023-11-29 05:14:18 24 4
gpt4 key购买 nike

嘿,我需要有关此编码的帮助,我不确定发生了什么。前几天还在工作。 if let ur; 之后出现错误= 元数据?.downladURL()

func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
guard let uid = Auth.auth().currentUser?.uid else { return }
let storageRef = Storage.storage().reference().child("user/\(uid)")

guard let imageData = UIImageJPEGRepresentation(image, 0.75) else { return }

let metaData = StorageMetadata()
metaData.contentType = "image/jpg"

storageRef.putData(imageData, metadata: metaData) { metaData, error in
if error == nil, metaData != nil {
if let url = metaData?.downloadURL() {
completion(url)
} else {
completion(nil)
}
// success!
} else {
// failed
completion(nil)
}
}
}

最佳答案

您可能已经更新了 Firebase Pod。在 Firebase 5.0 中,他们取消了 metaData?.downladURL() 函数。您必须遵循他们网站上的更新文档。从那里复制:

// Data in memory
let data = Data()

// Create a reference to the file you want to upload
let riversRef = storageRef.child("images/rivers.jpg")

// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can also access to download URL after upload.
riversRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
}
}

Firebase 存储:https://firebase.google.com/docs/storage/ios/upload-files

关于swift - 类型 'StorageMetadata' 的值没有成员 'downloadURL',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59340754/

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