I've been trying to upload an image to Firebase and then set it to be the profile picture of an user. For some reason the url address of the image is null and I believe it is something related to the metadata in this function:
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 = image.jpegData(compressionQuality: 0.5) else {return}
let metaData = StorageMetadata()
metaData.contentType = "image/jpg"
storageRef.putData(imageData, metadata: metaData) { metaData, error in
if error == nil, metaData != nil {
storageRef.downloadURL { url, error in
completion(url)
// success!
}
}
}
}
the url returned in complition is nil or error != nil, metaData == nil