使用putFIle Swift 5将视频上传到Firebase

问题描述 投票:0回答:1

我一直试图将视频从摄像头角色上传到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)
    }
swift firebase firebase-storage
1个回答
0
投票
中得到错误代码-1

最后弄清楚了,我应该从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)
    }
© www.soinside.com 2019 - 2024. All rights reserved.