In my app, users can select a photo from gallery to upload. After the user selects a photo, the following code gets called:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
}
I need to upload the image in this method, but I don't know how to upload this photo to my server. I can post text with following code but I don't know how to use this for photo/s:
let request = NSMutableURLRequest(URL: NSURL(string: "url")!)
request.HTTPMethod = "POST"
let postString = "username=\(self.username)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
}
task.resume()
How can I upload a selected photo to my server with above code?