迁移对我来说简直就是一场噩梦。我从以前的版本雨燕/的iOS/Alamofire如何在Alamofire4中进行multipartFormData上传?
let intVal = 0
Alamofire.upload(.POST, url, headers: ["StringValue": intVal, "StringValue2": "StringValue3"], multipartFormData: { mpfd in
let image = self.profileImageView.image!
let imageData = UIImageJPEGRepresentation(image, 0.8)!
mpfd.appendBodyPart(data: imageData, name: "image", fileName: "custom_image.jpg", mimeType: "image/jpeg")
}, encodingCompletion: { result in
switch result {
case .success(let request, _, _):
let response = request.response
print("response from image change: \(response)")
print("Successfully changed pro pic")
case .failure/*(let encodingError)*/:
print("Failed to change pro pic")
}
})
的这个老代码,但现在的Xcode是给我一个错误说“不明确提及成员“上传(_:到:方法:标题)”,但我不知道我是否可以信任这些错误消息,因为Alamofire会触发并且现在抛出数千个错误,例如encoding: .json
现在是JSONEncoding.default
,但是Xcode告诉我错误是“函数调用中的额外方法”。所以,我想大多数其他错误的解决方案是切换的方法和URL参数
Alamofire.upload(url, method: .post, headers ...)
但是,这也不能正常工作。我应该如何重写这个新的Swift/Alamofire?
[相关Q&A](http://stackoverflow.com/questions/41401913/cannot-invoke-append-with-an-argument-list- of-type-string-withname-string /) – dfri