I have dictionary whre i put some values
let params:[String:Any?]=[
            "upload":(postInfo["upload"]?.isEmpty)! ? nil : UIImage(data: Data.init(base64Encoded: postInfo["upload"]!)!),
            "type-place":postInfo["type-place"]!,
            "place":postInfo["place"]!,
            "city-place":postInfo["city-place"]!,
            "name-place":postInfo["name-place"]!,
            "web-site":postInfo["web-site"]!,
            "e-mail":postInfo["e-mail"]!,
            "mob-tel":postInfo["mob-tel"]!,
            "mob-tel-dop":postInfo["mob-tel-dop"]!,
            "adress":postInfo["adress"]!,
            "adressMapH":postInfo["adressMapH"]!,
            "content":postInfo["content"]!,
            "work-day":postInfo["work-day"]!,
            "priceS":postInfo["priceS"]!,
            "priceE":postInfo["priceE"]!,
            "countPlaceS":postInfo["countPlaceS"]!,
            "countPlaceE":postInfo["countPlaceE"]!,
            "link-vk":postInfo["link-vk"]!,
            "link-inst":postInfo["link-inst"]!,
            "link-fs":postInfo["link-fs"]!,
            "link-twitter":postInfo["link-twitter"]!,
            "upload1":(postInfo["upload1"]?.isEmpty)! ? nil : UIImage(data: Data.init(base64Encoded: postInfo["upload1"]!)!),
            "halal":(postInfo["properties"]?.contains("халяль"))! ? "1":"0",
            "wifi":(postInfo["properties"]?.contains("wi-fi"))! ? "1":"0",
            "card":(postInfo["services"]?.contains("оплата картой"))! ? "1":"0",
            "vip":(postInfo["services"]?.contains("гардероб"))! ? "1":"0",
            "parking":(postInfo["services"]?.contains("парковка"))! ? "1":"0",
            "garderob":(postInfo["services"]?.contains("гардероб"))! ? "1":"0",
            "upload2":postInfo["upload2"],
            "upload3":postInfo["upload3"],
            "isAkc":(postInfo["descActionSale"]?.isEmpty)! ? "0":"1",
            "descActionSale":postInfo["descActionSale"]!,
            "deposit":postInfo["deposit"]!
        ]
and in value upload2/upload3 i save base64String array.
I need to convert upload2/upload3 array to UIImageJPEGRepresentation and put it to multipart form data using Alamofire. There my code:
Alamofire.upload(multipartFormData: {
            multipartFormData in
            for (key,value) in params{
                if key == "upload2"{
                    for item in (params["upload2"] as! String).components(separatedBy: ","){
                        let decodedData = Data.init(base64Encoded: item, options: Data.Base64DecodingOptions.init(rawValue: 0))
                        if  let img=UIImage(data: decodedData!){
                            let m=UIImageJPEGRepresentation(img, 1)
                            multipartFormData.append(m!, withName: key, mimeType: "image/jpeg")
                        }
                    }
                }else if key == "upload3"{
                    for item in (params["upload3"] as! String).components(separatedBy: ","){
                        if  let img=UIImage(data: Data.init(base64Encoded: item)!){
                            let m=UIImageJPEGRepresentation(img, 1)
                            multipartFormData.append(m!, withName: key, mimeType: "image/jpeg")
                        }
                    }
                }else{
                    multipartFormData.append((value as! String).data(using: .utf8)!, withName: key)
                }
            }
        }, usingThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold, to: "http://kuda-poydem.kz/apitest.php?act=org_add&add-new-place=1", method: .post, headers: headers, encodingCompletion: {
            (encodingResult) in
            switch encodingResult{
            case .success(request: let upload, streamingFromDisk: _, streamFileURL: _):
                upload.responseJSON{
                    response in
                    print(response)
                }
                break
            default:
                break
            }
        })
Error is :
2016-11-15 13:38:18.027 kp[6504:146465] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (UIImage)'
