我需要在服务器上的base64中发送图像,但是我尝试了每种方法,但是仍然没有碰到错误500 Internal Server Error。 但是,当我尝试在POSTMAN上执行相同的操作时,效果很好。我附上了邮递员的屏幕截图。请帮助,从几天开始我就一直坚持下去。
func sendImageToServer(image:UIImage){
SVProgressHUD.show()
let imageData = image.jpegData(compressionQuality: 0.2)!.base64EncodedData()
Alamofire.upload(multipartFormData: { (multipartFormdata) in
multipartFormdata.append(imageData, withName: "image", fileName: "photo.png", mimeType: "image/png")
}, to: "http://35.180.52.242:5000/predict", method: .post, headers: headers()) { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
print(response)
SCLAlertView().showError("Error", subTitle: response.response?.description ?? "")
SVProgressHUD.dismiss()
}
case .failure(let encodingError):
print(encodingError)
SVProgressHUD.dismiss()
}
}
}
func headers()->HTTPHeaders{
return ["Content-Type": "application/json"] as HTTPHeaders
}
这是响应的样子。
- some:{URL:http://35.180.52.242:5000/predict} {状态代码:500,标题{ “内容长度” =( 291 ); “内容类型” =( “文本/ html” ); 日期=( “ 2019年2月22日星期五22:26:03 GMT” ); 服务器=( “ Werkzeug / 0.14.1 Python / 2.7.15” ); }}
答案 0 :(得分:1)
您可以尝试删除手动设置的标题headers: headers()
吗? Alamofire应该为多部分表单数据设置这些标题,并且我猜您正在用application/json