1

I want to know how to take an array of images by using UIImagePickerController and also post an array to the server and as well as get this an array of images from server by using JSON web services. And also I need to post image information (date of taking) to server.

I am getting image by using UIImagePickerController . Here is my code

-(IBAction)fileselectionAction:(id)sender{

    [self.view endEditing:YES];
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Pick Photo From" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Photo Album", @"Take New Photo", @"Cancel", nil];

    [actionSheet showFromToolbar:self.navigationController.toolbar];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.delegate = self;

    if (buttonIndex == 0) {
        //[self.imagePickerController setAllowsEditing:YES];
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        self.imagePickerController.allowsEditing = YES;
        [self presentViewController:self.imagePickerController animated:YES completion:nil];

    } else if (buttonIndex == 1) {

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self.imagePickerController setAllowsEditing:YES];
            //self.imagePickerController.showsCameraControls = YES;

            [self presentViewController:self.imagePickerController animated:YES completion:nil];

        }
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)info
{

   [picker dismissViewControllerAnimated:YES completion:nil];
    picker = nil;
    NSData *imageData = UIImageJPEGRepresentation(image,0.0);
    self.image1 = [UIImage imageWithData:imageData];
}

Thanks in advance.

xav
  • 5,452
  • 7
  • 48
  • 57
ssmanohar
  • 186
  • 1
  • 9
  • You can use be this library that will work on any kind of web service: github.com/mineshpurohit/ServiceCallingUtility – MinuMaster Nov 15 '14 at 07:00

2 Answers2

0

Doesn't the web service provide an API for sending images? If so, use this.

Otherwise, if you also develop the web service yourself, don't use JSON to embed images, instead use an appropriate content type.

If you absolutely have to use JSON, you need to encode the image to a JSON compatible string, e.g. base64, then send the image with accompanying meta data as a JSON string.

CouchDeveloper
  • 18,174
  • 3
  • 45
  • 67
  • - (NSString *)encodeToBase64String:(UIImage *)image { NSLog(@"\n The resulted string value is %@",[UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]); return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; } I am using above method but it's taking too much time and also i am getting big base64 string value. – ssmanohar Aug 11 '14 at 06:33
  • Encoding takes time, but it should be affordable. Typically, there is a space overhead of about 25% when encoding with base64 which is unavoidable. Due to this and other reasons, sending images as JSON isn't optimal. Use an approptiate content type as already mentioned. – CouchDeveloper Aug 11 '14 at 07:43
-1

You should send all those images one by one using with Multi-Part request. Following is the link to upload using AFNetworking.

https://github.com/AFNetworking/AFNetworking#post-multi-part-request

And for data taken; Images have metadata associated with them for date taken. You can extract dates from there.

Afnan
  • 888
  • 1
  • 13
  • 37