0

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)
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Jimmy Gonçalves
  • 79
  • 1
  • 2
  • 9

0 Answers0