Swift 3 Alamofire multipart upload
For example, using Alamofire 4.0.0 in Swift 3:
(make sure you are 4.0.0 ready as it looks like you haven't updated your Alamofire yet)
Alamofire.upload(multipartFormData: { (multipartFormData) in // code }, to: URL, encodingCompletion: { (result) in // code })
or
Alamofire.upload(multipartFormData: { (multipartFormData) in // code }, with: URL, encodingCompletion: { (result) in // code })
So headers
need to be passed by URL request:
let URL = try! URLRequest(url: "http://example.com", method: .get, headers: headers)
In swift 3, trying to set multipartFormData as @DCDC pointed out in his solution. XCode try to cast to AnyObject before .data(), so instead of
value.data(using: String.Encoding.utf8)!, withName: key
I did
[replace_your_var_name_here].data(using: String.Encoding.utf8)!, withName: key
In my case my var list was not big so hardcoding was an option.