I'm trying to compress an image before uploading to the server using UIImageJPEGRepresentation.
So far, I've changed the image to PNG and changed the quality to 0.01f. I've tried a few different ways of writing this.
Is this optimal before sending to the server? What should I change to optimize?
- (void)uploadPhoto {
WUTModelImageUploadReq *imageUploadReq = [[WUTModelImageUploadReq alloc]init];
imageUploadReq.photo = [self encodeToBase64String:[UIImage imageWithData:UIImageJPEGRepresentation(self.viewControllerPost.imageForPost, 0.01f)]];
imageUploadReq.extension = @"png";
void (^wsSuccessHandler)(AFHTTPRequestOperation *operation, NSDictionary* responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"Pull Feed responseObject %@",responseObject);
NSError *error;
WUTModelPostImageResponse *wsResponse = [[WUTModelPostImageResponse alloc]initWithDictionary:(NSDictionary *)responseObject error:&error];
if (error) {
errorMessage = @"Failure to upload image.";
[self postExecuteFail];
}
else{
if (wsResponse.success) {
WUTModelImage *imageTemp = [wsResponse.data firstObject];
[postItem setObject:imageTemp.photo forKey:@"photo"];
[self uploadPostFeed];
}else{
errorMessage = @"Failure to upload image.";
[self postExecuteFail];
}
}
};