-
-
Save axelrivera/6656374 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); | |
}]; | |
// 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