Skip to content

Instantly share code, notes, and snippets.

@venkatchm
Last active March 8, 2017 10:57
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 venkatchm/caa68485e2bfc7f954185b475bbb1eb7 to your computer and use it in GitHub Desktop.
Save venkatchm/caa68485e2bfc7f954185b475bbb1eb7 to your computer and use it in GitHub Desktop.
private static func upload(_ anything: AnyObject,
completion: @escaping (Result<CloudinaryResponse>) -> Void ) {
let transformation = CLTransformation()
transformation?.width = 720
transformation?.height = 1280
transformation?.audioCodec = .none
guard let _transformation = transformation else {
return
}
let eagerTransformation = CLEagerTransformation(dictionaries: [_transformation])
guard let _eagerTransformation = eagerTransformation else {
return
}
let options = ["resource_type": "video",
"format": mp4, "type": "authenticated", "eager" : _eagerTransformation, "eager_async": "true",
CloudinaryConstants.accessType: CloudinaryConstants.authenticated] as [String : Any]
do {
let cloudinary = try CLCloudinary(url: Configuration.cloudinaryURL())
let uploader = CLUploader(cloudinary, delegate: nil)
uploader?.upload(anything, options: options, withCompletion: {
(successResult, errorResult, code, idContext) in
if errorResult != nil {
completion(.failure(CloudinaryError.uploadFailed))
} else {
CloudinaryMapper.map(successResult, completion: completion)
}
}, andProgress: {
(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite, idContext) in
//TODO: (Venkatachalam) Need to update
print("byteswritten --\(bytesWritten)")
print("totalBytesWritten --\(totalBytesWritten)")
print("totalBytesExpectedToWrite \(totalBytesExpectedToWrite)")
})
}
catch {
completion(.failure(Error.customError(NSLocalizedString("Unknown.Error.Message", comment: ""))))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment