Reputation: 321
I have a parameter like "currentPhoto" and link API key as http://someapikey.
A user has to choose a photo from photo library and upload it to this link. I need to send this photo as a parameter.
Example:
The user chose a photo to let's name it as myPhoto. I need to send this photo to link http://someapikey as parameter "currentPhoto": myPhoto.
It should post request.
Upvotes: 1
Views: 473
Reputation: 850
You can try this code...
var strBase64: NSString!
let image = UIImage(named: "images.jpeg");
let imageData = UIImagePNGRepresentation(image!)! as NSData
strBase64 = imageData.base64EncodedString(options: .lineLength64Characters) as NSString
let url: String = "http://someapikey"
let parameter = ["currentPhoto": strBase64] as [String : Any]
Alamofire.request(url, method: .post, parameters: parameter, encoding: JSONEncoding.default)
.responseJSON { response in
debugPrint(response)
}
Upvotes: 1