Skip to content

Instantly share code, notes, and snippets.



Created May 11, 2015
What would you like to do?
upload image from UIPicker
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
// do something with selectedImage and originalImage
let timage = UIImageJPEGRepresentation(image, 1.0);
if image != nil {
//UIImageJPEGRepresentation(selectedImage, <#compressionQuality: CGFloat#>)
upload(.POST, "http://api.localhost/image", timage)
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
var fp : Float
if totalBytesWritten > 0 {
fp = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite);
dispatch_async(dispatch_get_main_queue()) {
self.progressView.setProgress(fp, animated: true)
.responseString { (request, response, jeson, error) in
picker.dismissViewControllerAnimated(true, completion:nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment