Reputation: 13
I'm trying convert code for Swift 3 and Alamofire 4, and I'm currently struggling with the following error:
Cannot call value of non-function type '((UInt) -> Data?)!'
at this line:
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
Please give your advice for this case. My current code is below.
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(imageData!, withName: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
}
},to:"uploadimgURL"
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _)
upload.responseString(completionHandler: { (response) in
debugPrint(response)
})
case .failure(let encodingError):
print(encodingError)
}
}
)
Upvotes: 0
Views: 675
Reputation: 7419
I do see one issue with the line in question. Try not using the raw value of the enum like so:
let stringValue = value as! String
multipartFormData.append(data: stringValue.data(using: .utf8)!, name: key)
Upvotes: 2