I need to upload a video to server using Alamofire. The user selects the video from device and I get URL in didFinishPickingMediaWithInfo successfully as follows:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let ivHandler = LocalImageVideoHandler()
let videoUrl = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL?
let pathString = videoUrl??.filePathURL
self.dismiss(animated: true)
}
And then I upload the video using the following code:
func uploadPostFiles(imageVideoPath:String,parameters:Parameters) {
AF.upload(multipartFormData: { multipartFormData in
// Selected Video Path/URL = "file:///private/var/mobile/Containers/Data/PluginKitPlugin/51D56143-9303-407D-8E37-AAC576766407/tmp/trim.59847342-DD95-4B74-A7BE-82BA0F3D706E.mp4"
multipartFormData.append(URL(string: imageVideoPath )!, withName: "file", fileName: "trim.59847342-DD95-4B74-A7BE-82BA0F3D706E.mp4",mimeType: "video/mp4")
for (key, value) in parameters {
if let temp = value as? String {
multipartFormData.append(temp.data(using: .utf8)!, withName: key)
}
}
}, to: ApiConstant.BASE_URL+"/upload", method: .post, headers: getHeaders().self)
.validate(statusCode: 200..<500)
.response { response in
if response.data != nil&&response.response?.statusCode==200 {
do {
let users = try JSONDecoder().decode(GetPostModel.self
, from: response.data!)
debugPrint(users)
if(users.status){
}else{
}
} catch let error as NSError {
}
}else{
}
}
It enters in the failure block, and the following error displays:
The URL provided is a directory:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/51D56143-9303-407D-8E37-AAC576766407/tmp/trim.3751F517-4A5D-43C3-B8ED-BC41313653FE.mp4