How to upload video file to AWS in background?

I have query regarding Uploading videos in Background like whats app in swift .shall we use Background identifier or any ideas?

1 answer

  • answered 2018-09-19 06:44 Naresh

    Use alamofire for this. For Almofire read Tutorial

    Video will be sent as stream of data. Convert the video to data then send to server with this function.

    //This function will send the stream of data to server.
    
        let videoData = Data() //you need proper video data here.
        let url = URL.init(string: "URL to upload")  //place your valid url here.
    
        Alamofire.upload( multipartFormData: { multipartFormData in
            multipartFormData.append(videoData, withName: "video", fileName: "video.mp4", mimeType: "video/mp4")
    
        }, to: url!, encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseJSON { response in
                    if let JSON = response.result.value {
                        print("SUCCESS\n\n", JSON)
                    } else {
                        print("FAILED\n\n", response)
                    }
                }
            case .failure(let encodingError):
                print(encodingError)
            }
        })