Skip to content

Instantly share code, notes, and snippets.

@fel-cesar
Created October 21, 2016 10:52
Show Gist options
  • Save fel-cesar/c638b5bb47d57f4050c4232feee64d51 to your computer and use it in GitHub Desktop.
Save fel-cesar/c638b5bb47d57f4050c4232feee64d51 to your computer and use it in GitHub Desktop.
Example CloudStorage Swift 3
//let cloudStorage : CloudStorageProtocol = Box.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = GoogleDrive.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = OneDrive.init(clientId: "ClientID", clientSecret: "ClientSecret")
//let cloudStorage : CloudStorageProtocol = Dropbox.init(clientId: "ClientID", clientSecret: "ClientSecret")
let cloudStorage : CloudStorageProtocol = Egnyte.init(domain: "DOMAIN", clientId: "[CLIENT]", clientSecret: "[SECRET]", redirectUri: "[REDIRECTURI]", state: "ANY")
let path = Bundle.main.path(forResource: "UserData", ofType: "csv")!
let fileAttributes = try! FileManager.default.attributesOfItem(atPath: path)
let fileSize: UInt64 = fileAttributes[FileAttributeKey.size] as! UInt64
let stream = InputStream.init(fileAtPath: path)!
DispatchQueue.global(qos: .background).async {
DispatchQueue.main.async {
do{
try cloudStorage.uploadFileToPath(path, stream: stream, size: CLong(fileSize), overwrite: false)
} catch let error{
print("An error: \(error)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment