// swift 5
static func postComplexPictures(url:URL, params:[String:Any],pictures : UIImage, finish: @escaping ((message:String, list:[[String: Any]],isSuccess:Bool)) -> Void) {
var result:(message:String, list:[[String: Any]],isSuccess:Bool) = (message: "Fail", list:[],isSuccess : false)
let headers: HTTPHeaders
headers = ["Content-type": "multipart/form-data",
"Content-Disposition" : "form-data"]
AF.upload(multipartFormData: { (multipartFormData) in
for (key, value) in params {
multipartFormData.append((value as! String).data(using: String.Encoding.utf8)!, withName: key)
}
if let imageData = pictures.pngData() {
multipartFormData.append(imageData, withName: "document", fileName: "document.png", mimeType: "image/png")
}
}, usingThreshold: UInt64.init(), to: url, method: .post, headers: headers).response{ response in
if((response.error != nil))
{
do
{
if let jsonData = response.data
{
let parsedData = try JSONSerialization.jsonObject(with: jsonData) as! Dictionary<String, AnyObject>
print(parsedData)
let status = parsedData["status"] as? NSInteger ?? 0
let msg = parsedData["message"] as? String ?? ""
if(status==1)
{
result.isSuccess = true
result.message=msg
if let jsonArray = parsedData["data"] as? [[String: Any]] {
result.list=jsonArray
}
}
else
{
result.isSuccess = false
result.message=msg
}
}
finish(result)
}
catch
{
finish(result)
}
}
else
{
finish(result)
}
}
}