Last active
October 11, 2016 10:06
-
-
Save bhameyie/55eb51b58e05d4096c95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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