Я работаю над загрузкой изображения, используя multipart.Этот код Работает нормально в swift 4 и Alamofire 4. Пожалуйста, дайте какое-либо решение для этого.
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")
}
})}
Заранее спасибо.