我正在尝试使用此代码使用Alamofire上传(其中photo.image是UIImage)
let imageData = UIImageJPEGRepresentation(photo.image, 1.0)
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(data: imageData!, withName: "unicorn")
},
to: "https://httpbin.org/post",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
然而,这告诉我“表达式类型'()'在没有更多上下文的情况下是不明确的。
我不确定我在这里做错了什么,并且会喜欢一些建议。
答案 0 :(得分:1)
multipartFormData
我有错误的论据。这是有效的:
multipartFormData: { multipartFormData in
multipartFormData.append(imageData!, withName: "photo", fileName: "image.jpg", mimeType: "image/jpg")
},