it has been 5 hours and I have no idea why I am getting this error.
Optional("File at URL: file:///private/var/mobile/Containers/Data/PluginKitPlugin/C6000DDA-6EE8-4DB3-A360-6DDE9EDCA730/tmp/trim.AD2C231C-65C6-4562-A332-39907709ECA0.MOV is not reachable.")
I have a photo picker that only shows the videos and I want to upload the video selected to firebase. I have no idea why I am getting this error. I can upload any video without the photo picker and it works normally so the problem is not with firebase, it is from the swift code.
Here is my code:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedVideo = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL {
print("PICKED VIDEO")
print("FIRST URL")
print(pickedVideo)
// try to upload here
let url = URL(fileURLWithPath: pickedVideo.absoluteString!)
print("NEW URL")
print(url)
let storageReference = Storage.storage().reference().child("upload")
// Start the video storage process
storageReference.putFile(from: url , metadata: nil, completion: { (metadata, error) in
if error == nil {
print("Successful video upload")
storageReference.downloadURL { (url, error) in
// Add a new document with a generated ID
let db = Firestore.firestore()
var ref: DocumentReference? = nil
ref = db.collection("Posts").addDocument(data: [
"caption": "self.CaptionTextField.text!",
"isOnlyForMembers": "self.isOnlyForMembers!",
"url": url!,
"numberOfLikes": 0,
"time": Timestamp(date: Date())
]) { err in
if let err = err {
print("Error adding document: \(err)")
} else {
print("Document added with ID: \(ref!.documentID)")
db.collection("Posts").document(ref!.documentID).setData(["ID": ref!.documentID], merge: true)
// self.activityIndi.stopAnimating()
// self.performSegue(withIdentifier: "topostedsuccess", sender: self)
}
}
}
} else {
print(error?.localizedDescription)
}
})
}
}