Swift 3和IBM Cloudant上传图像

时间:2017-05-23 13:37:20

标签: swift3 cloud image-uploading

我尝试了很多东西,用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)
}

0 个答案:

没有答案