How to send a photo as parameter

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.

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.

1 answer

  • answered 2017-06-17 19:44 Samiul Islam Sami

    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