I am working on uploading image using multipart. This Code Working fine in swift 4 and Alamofire 4. Please give any solution for this.
public class func callsendImageAPI(param:[String: Any],arrImage:[UIImage],imageKey:String,URlName:String,controller:UIViewController, withblock:@escaping (_ response: AnyObject?)->Void){ Alamofire.upload(multipartFormData:{ MultipartFormData in for (key, value) in param { MultipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key) } for img in arrImage { guard let imgData = img.jpegData(compressionQuality: 1) else { return } MultipartFormData.append(imgData, withName: imageKey, fileName: FuncationManager.getCurrentTimeStamp() + ".jpeg", mimeType: "image/jpeg") } },usingThreshold:UInt64.init(), to: "URL", method:.post, headers:["Content-type": "multipart/form-data", "Content-Disposition" : "form-data"], encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, , ): upload.uploadProgress(closure: { (Progress) in print("Upload Progress: \(Progress.fractionCompleted)") }) upload.responseJSON { response in switch(response.result) { case .success(_): let dic = response.result.value as! NSDictionary if (dic.object(forKey: "status")! as! Int == 1){ withblock(dic.object(forKey: "data") as AnyObject) }else if (dic.object(forKey: Message.Status)! as! Int == 2){ print("error message") }else{ print("error message") } case .failure(_): print("error message") } } case .failure(let encodingError): print("error message") } })} Thanks in advance.