Reputation: 1809
I have an Alamofire request
let parameters = ["key1":value1, "key2":value2, "keyn":valueN] as [String: AnyObject]
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON, headers: ["Authorization": auth_token]).validate().responseObject() {
// etc
}
But I need to add a jpg image under an "image" key to the body of the HTTP request, how can I do this? I'm having trouble finding a simple Alamofire solution for this. I need to keep the current parameters but also send an image along with the POST in the body of the request
Upvotes: 0
Views: 603
Reputation: 1727
How about converting the image to base64?
if let imageData = UIImageJPEGRepresentation(selectedImage, 0.30)
{
let strBase64:String = imageData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
}
*I'm compressing the quality here as well.
Upvotes: 1