How can I upload with my own headers using Alamofire v4? In case of v3, I made my own function for that like following codes, but I can't do the same thing with v4.
static func upload(method: Alamofire.Method, urlString: String, multipartFormData: (data: Alamofire.MultipartFormData) -> (), completionHandler: (
response: Response<AnyObject, NSError>, statusCode:Int, json:JSON) -> ()){
Alamofire.upload(method, urlString, headers: MyRequest.makeHeaders(), multipartFormData: multipartFormData, encodingCompletion: {
encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
switch response.result {
case .Failure:
log.error("Upload request failed!!")
case .Success:
completionHandler(response: response, statusCode: (response.response?.statusCode)!, json:JSON(response.result.value!))
}
}
case .Failure(let error):
log.warning((error as NSError).localizedDescription)
}
})
}
and I tried with following code, but It doesn't work
static func upload(_ method: Alamofire.HTTPMethod, urlString: String, multipartFormData: (Alamofire.MultipartFormData) -> Swift.Void, completionHandler: @escaping
(_ response: NSDictionary, _ statusCode:Int, _ json:JSON) -> Void){
Alamofire.upload(multipartFormData: multipartFormData, to: urlString, method: method, headers: MyRequest.makeHeaders(), encodingCompletion: {
encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
switch response.result {
case .failure:
log.error("Upload request failed!!")
case .success:
completionHandler(response: response, statusCode: (response.response?.statusCode)!, json:JSON(response.result.value!))
}
}
case .failure(let error):
log.warning((error as NSError).localizedDescription)
}
})
}