我尝试了很多东西,用Swift上传一个简单的UIImage
给IBM Cloundant但没有任何成功。我也试过Alamofire。
请帮帮我。
let imageData = UIImagePNGRepresentation(imageToUpload)
Alamofire.upload(imageData!, to: url)
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}
错误类型错误,需要JSON
。所以我试着这样:
let imageData = UIImagePNGRepresentation(imageToUpload)
let dict = ["image": imageData]
let data = try? JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
Alamofire.upload(data!, to: url)
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}