Попробуйте это. Это решает мою проблему
class func uploadImage(_ strURL: String, parameters: [String: Any]?,image: UIImage?,keyImage : String, success:@escaping apiSuccess, failure:@escaping apiFailure) {
print(parameters as Any)
var UrlFinal = ""
do
{
try UrlFinal = baseURL + strURL.asURL().absoluteString
}
catch{
}
Alamofire.upload(
multipartFormData: { MultipartFormData in
for (key, value) in (parameters)! {
print((key, value))
MultipartFormData.append((value as! String).data(using: String.Encoding.utf8)!, withName: key)
}
if image != nil{
guard let imageData = image!.jpegData(compressionQuality: 1) else { return }
MultipartFormData.append(imageData, withName: keyImage, fileName: "file1.jpeg", mimeType: "image/jpeg")
}
}, to: UrlFinal) { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
if let res = response.result.value{
print(res)
Global.appDelegate.hideLoader()
success(res)
}else{
}
}
case .failure(let encodingError):
print(encodingError)
failure(encodingError)
}
}
}