我正在尝试使用params上传文件,但它失败了。 下面的代码有问题吗?
参考 Uploading file with parameters using Alamofire
夫特
Alamofire.upload(.POST, url, multipartFormData: { (multipartFormData) -> Void in
let fd = UIImageJPEGRepresentation(image,0.8)!
multipartFormData.appendBodyPart(data: fd, name: "image", fileName: "image.jpg", mimeType: "image/jpeg")
for (k, v) in params {
let d = v.dataUsingEncoding(NSUTF8StringEncoding)!
multipartFormData.appendBodyPart(data: d, name: k)
}
}) { (encodingResult) -> Void in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
if response.result.isSuccess {
print("success")
} else {
print("fail")
}
}
case .Failure(let encodingError):
self.view.makeToastCenter(message: "fail \(encodingError)")
}