Created
September 22, 2013 03:05
-
-
Save anonymous/6656327 to your computer and use it in GitHub Desktop.
This file contains 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
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