【发布时间】:2017-02-10 02:45:30
【问题描述】:
我正在执行以下操作以上传带参数的 PNG 文件:
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
// Send parameters
multipartFormData.append((UserDefaults.standard.value(forKey: Email) as! String).data(using: .utf8)!, withName: "email")
multipartFormData.append("png".data(using: .utf8)!, withName: "type")
},
to: "user/picture",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint("SUCCESS RESPONSE: \(response)")
}
case .failure(let encodingError):
self.removeSpinnerFromView()
print("ERROR RESPONSE: \(encodingError)")
}
}
)
问题是在我的服务器上我看不到 email 和 type 表单字段。我遵循了在线发布的示例。我应该为此做些什么不同的事情吗?
编辑
如果我删除我放置的部分:
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
THEN 包含参数。否则不是,我认为这是 Alamofire 4.0.1 中的一个错误。
【问题讨论】: