我一直试图将视频从摄像头角色上传到Firebase,但无法正常工作。
URL可以正常打印,但不确定为什么它不能正常工作。我在控制台中收到错误代码-1:
<< 1>完成,错误为[-1]错误域= NSURLErrorDomain代码= -1“未知错误”]
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let videoURL = info[.mediaURL] as? URL {
print("Here is the URL: \(videoURL)")
let filename = "Videos/trialVideo.mov"
Storage.storage().reference().child(filename).putFile(from: videoURL, metadata: nil) { (metadata, error) in
if error != nil {
print("**** ERROR MESSAGE *** \(error?.localizedDescription)")
return
}
}
}
videoPicker.dismiss(animated: true, completion: nil)
}
最后弄清楚了,我应该从NSURL对象创建URL(对此是新的,如果那不是正确的术语,请更正我)
更新的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let videoURL = info[.mediaURL] as? NSURL {
print("Here is the URL: \(videoURL)")
let url: URL = videoURL.absoluteString!
let filename = "Videos/trialVideo.mov"
Storage.storage().reference().child(filename).putFile(from: url, metadata: nil) { (metadata, error) in
if error != nil {
print("**** ERROR MESSAGE *** \(error?.localizedDescription)")
return
}
}
}
videoPicker.dismiss(animated: true, completion: nil)
}