已经5个小时了,我不知道为什么会收到此错误。
可选(“ URL上的文件:file:///private/var/mobile/Containers/Data/PluginKitPlugin/C6000DDA-6EE8-4DB3-A360-6DDE9EDCA730/tmp/trim.AD2C231C-65C6-4562- A332-39907709ECA0.MOV无法访问。“)
我有一个仅显示视频的照片选择器,我想将选择的视频上传到Firebase。我不知道为什么会收到此错误。我可以在不使用照片选择器的情况下上传任何视频,并且该视频可以正常运行,因此问题不在于firebase,而在于快速代码。
这是我的代码:
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)
}
})
}
}