I tried a lot of things to upload a simple UIImage
to IBM Cloundant with Swift without any success. I also tried Alamofire.
Please help me.
let imageData = UIImagePNGRepresentation(imageToUpload)
Alamofire.upload(imageData!, to: url)
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}
The error is bad type, it needs to be JSON
. So I tried like that:
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)
}