Created
December 2, 2013 08:18
-
-
Save corinnekrych/7746558 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
- (void)uploadImage:(UIImage*)image | |
{ | |
NSData *imageData = UIImageJPEGRepresentation(image, 0.6); | |
// 1 | |
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
config.HTTPMaximumConnectionsPerHost = 1; | |
[config setHTTPAdditionalHeaders:@{@"Authorization": [Dropbox apiAuthorizationHeader]}]; | |
// 2 | |
NSURLSession *upLoadSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; | |
// for now just create a random file name, dropbox will handle it if we overwrite a file and create a new name.. | |
NSURL *url = [Dropbox createPhotoUploadURL]; | |
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; | |
[request setHTTPMethod:@"PUT"]; | |
// 3 | |
self.uploadTask = [upLoadSession uploadTaskWithRequest:request fromData:imageData]; | |
// 4 | |
self.uploadView.hidden = NO; | |
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; | |
// 5 | |
[_uploadTask resume]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment