我的后端服务器图像的多部分/相关数据。如何使用Alamofire在iOS客户端中处理它?
答案 0 :(得分:0)
要从IOS上传多部分图片,示例代码如下:
if let URL = try? URLRequest(url: url, method: .post, headers: nil) {
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(image, 0.001), withName: "file", fileName: params.imageName, mimeType: "image/jpeg")
}, with: URL) { (result) in
switch result {
case .success(let upload, _, _):
//Enter Success Code
case .failure:
//Enter failure Code
}
}
希望有帮助。