我想从 Imagepicker 中选择视频,然后我想在 firebase 中发送视频并检索它

I want to pick video from Imagepicker then I want to send video in firebase and retrieve it

我想从 Images Picker 中选择视频,然后我想在 firebase 中发送视频并检索它请在 swift 中提供代码 5,我也编写用于在 firebase 上发送视频的代码

func downloadImages(folderPath:String,success:@escaping (_ image:UIImage)->(),failure:@escaping (_ error:Error)->()){
        
            // Create a reference with an initial file path and name
            let reference = Storage.storage().reference(withPath: "\(folderPath)")
            reference.getData(maxSize: (1 * 1024 * 1024 * 1024 * 1024 * 1024)) { (data, error) in
                if let _error = error{
                    print(_error)
                    failure(_error)
                } else {
                    if let _data  = data {
                        let myImage:UIImage! = UIImage(data: _data)
                        success(myImage)
                    }
                }
        
        }
     }

在 firebase 上上传视频存储是

func upload(file: URL, completion: @escaping ((_ url : URL?) -> ())) {
    let name = "\(Int(Date().timeIntervalSince1970)).mp4"
    do {
        let data = try Data(contentsOf: file)
        
        let storageRef =
    Storage.storage().reference().child("Videos").child(name)
        if let uploadData = data as Data? {
            let metaData = StorageMetadata()
    metaData.contentType = "video/mp4"
    storageRef.putData(uploadData, metadata: metaData
                , completion: { (metadata, error) in
        if let error = error {
            completion(nil)
        }
        else{
        storageRef.downloadURL { (url, error) in
                guard let downloadURL = url else {
            completion(nil)
            return
            }
            completion(downloadURL)
                }
            print("success")
                                }
                               })
        }
    }catch let error {
        print(error.localizedDescription)
    }
    
}

并从 firebase 获取视频

 let reference = Storage.storage().reference().child("Videos").child(folderPath)
    reference.getData(maxSize: INT64_MAX) { (data, error) in
            if let error = error {
                print("Error downloading image data: \(error)")
                return
            }
            reference.getMetadata(completion: { (metadata, metadataErr) in

                if let error = metadataErr {
                    print("Error downloading metadata: \(error)")
                    return
                }
                else {
                    reference.downloadURL { URL, error in
                       completion(URL)
                        print(URL)
                    }