Created
July 23, 2012 15:33
-
-
Save jimjeffers/3164258 to your computer and use it in GitHub Desktop.
File upload process for CAMM resizing image, utilizing parse, and communicating to web view.
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)imagePickerController:(UIImagePickerController *)picker | |
didFinishPickingMediaWithInfo:(NSDictionary *)info { | |
// Hide the image picker. | |
[picker dismissModalViewControllerAnimated:YES]; | |
// Reference the image from the picker. | |
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; | |
// Use the size of the image to calculate its aspect ratio. | |
float aspectRatio = image.size.width/image.size.height; | |
// Resample the image so that it is 800x? for web purposes. | |
UIImage *scaledImage = [image scaleToSize:CGSizeMake(600.0f*aspectRatio, 600.0f)]; | |
// Free the reference to the original image. | |
image = nil; | |
// We'll transmit a JPEG representation compressed at 20% quality. | |
NSData *imageData = UIImageJPEGRepresentation(scaledImage, 0.2); | |
// We'll use the current timestamp for the filename: | |
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970]; | |
// NSTimeInterval is defined as double | |
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp]; | |
NSString *fileName = [NSString stringWithFormat:@"%@.jpg", [timeStampObj stringValue], nil]; | |
// Transmit the file to parse. | |
PFFile *imageFile = [PFFile fileWithName:fileName data:imageData]; | |
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { | |
NSString *javascript = [NSString stringWithFormat:@"setReportType(\"%@\"); readyDocument(); setImagePath(\"%@\");", reportType, imageFile.url, nil]; | |
[reportWebView stringByEvaluatingJavaScriptFromString:javascript]; | |
javascript = nil; | |
} progressBlock:^(int percentDone) { | |
NSLog(@"Percent: %i",percentDone); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment