Skip to content

Instantly share code, notes, and snippets.

@slav123
Created May 11, 2015 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slav123/5bc82bb48749ac13926a to your computer and use it in GitHub Desktop.
Save slav123/5bc82bb48749ac13926a to your computer and use it in GitHub Desktop.
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
println(jeson)
println(response)
}
}
picker.dismissViewControllerAnimated(true, completion:nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment