Skip to content

Instantly share code, notes, and snippets.

@fel-cesar
Last active October 21, 2016 10:10
Show Gist options
  • Save fel-cesar/f7a038b7a6ee88e403bdc47dd7afcaf3 to your computer and use it in GitHub Desktop.
Save fel-cesar/f7a038b7a6ee88e403bdc47dd7afcaf3 to your computer and use it in GitHub Desktop.
Example CloudStorage Objective-C
// id<CRCloudStorageProtocol> cs = [[CROneDrive alloc] initWithClientId:@"[CLIENT]" clientSecret:@"[SECRET]"];
// id<CRCloudStorageProtocol> cs= [[CRGoogleDrive alloc] initWithClientId:@"[CLIENT]" clientSecret:@"[SECRET]"];
// id<CRCloudStorageProtocol> cs = [[CRBox alloc] initWithClientId:@"[CLIENT]" clientSecret:@"[SECRET]" ];
// id<CRCloudStorageProtocol> cs = [[CRDropbox alloc] initWithClientId:@"[CLIENT]" clientSecret:@"[SECRET]"];
id<CRCloudStorageProtocol> cs = [[CREgnyte alloc] initWithDomain:@"[DOMAIN]" clientId:@"[CLIENT]" clientSecret:@"" redirectUri:@"[SECRET]" state:@"ANY"];
NSString * path = [[NSBundle mainBundle] pathForResource:@"UserData" ofType:@"csv"];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
long fileSize = [fileAttributes fileSize];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
NSInputStream * stream = [NSInputStream inputStreamWithFileAtPath:path];
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
@try {
[cs uploadFileToPath:@"/Shared/Documents/TestFolder/Data.csv" withStream:stream size:fileSize overwrite:NO];
} @catch (NSException *exception) {
//TODO: Exception handling
} @finally {
//TODO: close the stream
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment