Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Last active October 11, 2016 10:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhameyie/55eb51b58e05d4096c95 to your computer and use it in GitHub Desktop.
Save bhameyie/55eb51b58e05d4096c95 to your computer and use it in GitHub Desktop.
//NOTE: written in older version of Swift back in January 2015. Swift has since changed a bit.
import Foundation
import UIKit
class UploadViewController: UIViewController,CLUploaderDelegate
{
@IBOutlet weak var capturedImage: UIImageView!
var Cloudinary:CLCloudinary!
var image:UIImage?
override func viewDidLoad() {
super.viewDidLoad()
capturedImage.image = image
Cloudinary = CLCloudinary(url: "cloudinary://yours:yours")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func uploadItem(sender: AnyObject) {
let fileId = "YOUR/FILE/ID"
uploadToCloudinary(fileId)
}
func uploadDetailsToServer(fileId:String){
//upload your metadata to your rest endpoint
}
func uploadToCloudinary(fileId:String){
let forUpload = UIImagePNGRepresentation(self.image) as NSData
let uploader = CLUploader(Cloudinary, delegate: self)
uploader.upload(forUpload, options: ["public_id":fileId],
withCompletion:onCloudinaryCompletion, andProgress:onCloudinaryProgress)
}
func onCloudinaryCompletion(successResult:[NSObject : AnyObject]!, errorResult:String!, code:Int, idContext:AnyObject!) {
let fileId = successResult["public_id"] as String
uploadDetailsToServer(fileId)
}
func onCloudinaryProgress(bytesWritten:Int, totalBytesWritten:Int, totalBytesExpectedToWrite:Int, idContext:AnyObject!) {
//do any progress update you may need
}
func setImage(img:UIImage!){
image = img
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment