Skip to content

Instantly share code, notes, and snippets.

@axelrivera
Forked from anonymous/gist:6656327
Last active December 23, 2015 15:38
Show Gist options
  • Save axelrivera/6656374 to your computer and use it in GitHub Desktop.
Save axelrivera/6656374 to your computer and use it in GitHub Desktop.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(_site.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(_site.frame.size);
}
[_site.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSURL *url = [NSURL URLWithString:@"http://ec2-54-200-77-159.us-west-2.compute.amazonaws.com:3000"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImagePNGRepresentation(viewImage);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/photo" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"map" fileName:@"map.png" mimeType:@"image/png"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
// This should work... you owe me mother fucker!!!
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Response Object Should be an NSDictionary
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[httpClient enqueueHTTPRequestOperation:operation];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment