Created
February 8, 2013 09:45
-
-
Save PaulWoodIII/4737758 to your computer and use it in GitHub Desktop.
A function to post an image onto ADN
This does not work. Trying to figure out why
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)postImage{ | |
| // Get a ADN Token | |
| NSString *access_token = @"foobar"; | |
| NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net"]; | |
| AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; | |
| [httpClient setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Bearer %@", access_token]]; | |
| NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"bird.jpg"], 0.5); | |
| NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" | |
| path:@"/stream/0/files" | |
| parameters:nil | |
| constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { | |
| [formData appendPartWithFileData:imageData name:@"content" fileName:@"bird.jpg" mimeType:@"image/jpeg"]; | |
| }]; | |
| AFJSONRequestOperation *operation = | |
| [AFJSONRequestOperation JSONRequestOperationWithRequest:request | |
| success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { | |
| NSLog(@"Success :%@", JSON); | |
| } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { | |
| NSLog(@"Failure: %@", error); | |
| }]; | |
| [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { | |
| NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); | |
| }]; | |
| [httpClient enqueueHTTPRequestOperation:operation]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment