Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2013 03:05
Show Gist options
  • Save anonymous/6656327 to your computer and use it in GitHub Desktop.
Save anonymous/6656327 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);
}];
[httpClient enqueueHTTPRequestOperation:operation];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment