Can anyone help me in this problem . So I have a code for Firebase Storage using metadata, on Swift 4
Here is the code :
let imageName = NSUUID().uuidString
let storageRef = Storage.storage().reference().child("profile_images").child("\(imageName).png")
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil {
print(error)
return
}
if let profileImageUrl = metadata?.downloadURL()?.absoluteString {
let values = ["name": name, "email": email, "profileImageUrl": profileImageUrl]
self.registerUserIntoDatabaseWithUID(uid, values: values as [String : AnyObject])
}
print(metadata)
})
and i have error in :
if let profileImageUrl = metadata?.downloadURL()?.absoluteString
the error :
Value of type 'StorageMetadata?' has no member 'downloadURL'
This is the screenshot of my code click here
Is there a solution , thanks anyway
From the error, it says metadata has no member downloadURL. so, it is removed from the StorageMetadata on firebase. You can do it like this.
let imageName = NSUUID().uuidString
let storageRef = Storage.storage().reference().child("profile_images").child("\(imageName).png")
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil {
print(error)
return
}
storageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
print("an error occurred!")
return
}
let profileImageUrl = downloadURL.absoluteString
let values = ["name": name, "email": email, "profileImageUrl": profileImageUrl]
self.registerUserIntoDatabaseWithUID(uid, values: values as [String : AnyObject])
print(metadata)
}
})
Detailed explanation is here at official doc
Try and share the results.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.