3

I am trying to upload an .mp4 file I record from the iPhone but it sents a .mov to the API instead.I am checking the video URL path before the call and I can confirm the write to file works as expected. How can I change that ?

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        print("didFinishPickingMediaWithInfo")
        if let pickedVideo:NSURL = (info[UIImagePickerControllerMediaURL] as? NSURL) {

            let videoData : Data!
            do {
                try videoData = Data(contentsOf: pickedVideo as URL)
                var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
                let documentsDirectory = paths[0]
                let tempPath = documentsDirectory.appendingFormat("/vid1.mp4")
                let url = URL(fileURLWithPath: tempPath)
                do {
                    try _ = videoData.write(to: url, options: [])
                }
                uploadVideoToAPI(tempPath)
            }
}

func uploadVideoToAPI(tempPath:String) {
       API.uploadVideo(URL(fileURLWithPath:tempPath)
}

class func uploadVideo(videoUrl:URL) {
        Alamofire.upload(
            multipartFormData: { multipartFormData in
                multipartFormData.append(videoUrl, withName: "profileVideo", fileName: "video.mp4", mimeType: "video/mp4")
        },
            to: "\(baseUrl)",method: 
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        debugPrint(response)
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }
        }
        )
    }
PoolHallJunkie
  • 1,345
  • 14
  • 33
  • try this: `multipartFormData.appendBodyPart(fileURL: NSBundle.mainBundle().URLForResource("video", withExtension: "mp4")!, name: "video", fileName: "video.mp4", mimeType: "video/mp4")` to be sure there is nothing wrong in the way you upload the video. if the problem still exist let us know. – Mina Jan 10 '17 at 16:22
  • I am using the same to create the path , bodypart is not there in Swift 3. – PoolHallJunkie Jan 10 '17 at 16:28
  • I am also facing the same issue. Any help please – pkc456 Aug 31 '17 at 10:59

0 Answers0