Last active
March 8, 2017 10:57
-
-
Save venkatchm/caa68485e2bfc7f954185b475bbb1eb7 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
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