iPhone Developer Help

Full Version: Upload Captured Image with HTTP POST
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to send an image captured by the camera to an HTTP server.

1. Does anyone know how to simulate the camera on the simulator ?

Assuming this is not possible (I don't have me developer certificate yet) I have resorted to picking up an image from the default photo library that comes with the simulator.

2. Does anyone know how to add my own photos to this simulator gallery ?

Following is my code where I pick up the image from the photo library. The (void)useImageSadUIImage*)theImage function is called when the image is selected. This is what I want to send via an HTTP POST request to an HTTP server.

3. How do I convert the UIImage to a binary data format that the NSMutableURLRequest setHTTPBody function can use ?

Code:
-(BOOL)snapAction:(id)sender
{

    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsImageEditing = YES;

    // Picker is displayed asynchronously.
    [[self navigationController] presentModalViewController:picker animated:YES];
    return YES;

}

- (void)imagePickerController:(UIImagePickerController *)picker
                    didFinishPickingImage:(UIImage *)image
                    editingInfo:(NSDictionary *)editingInfo
{
    [self useImage:image];
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

// Implement this method in your code to do something with the image.
- (void)useImage:(UIImage*)theImage
{
}


Thanks,
Sajid

sdalvi Wrote:
3. How do I convert the UIImage to a binary data format that the NSMutableURLRequest setHTTPBody function can use ?


I think I figured this out ...

NSData * imageData = UIImagePNGRepresentation(theImage);
NSUInteger imageSize= imageData.length;

Sajid

Hi Sajid,

did you ever figure out how to use the Image Picker Control in the Simulator to shoot a photo or how to add a new photo to the gallery?

I also could make use of this functionality to showcase our demo.


Cheers, Ernst.

ernst42 Wrote:
Hi Sajid,

did you ever figure out how to use the Image Picker Control in the Simulator to shoot a photo or how to add a new photo to the gallery?

I also could make use of this functionality to showcase our demo.


Cheers, Ernst.


i kinda worked around the issue.

1. this is how i launched the photo library;

Code:
- (void)startActionid)sender
{

UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsImageEditing = YES;

// Picker is displayed asynchronously.
[[self navigationController] presentModalViewControllericker animated:YES];
}

- (void)imagePickerControllerUIImagePickerController *)picker
didFinishPickingImageUIImage *)image
editingInfoNSDictionary *)editingInfo
{

[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[self useImage:image];
}

- (void)imagePickerControllerDidCancelUIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}

2. note that when the image is picked up, didFinishPickingImage is called, in which I have a call to my function:

Code:
[self useImage:image];

3. I then overwrite the picked up image with the image i want.

Code:
- (void)useImageUIImage*)theImage
{

UIViewController *searchViewController = [[UIViewController alloc] init];

UIImage *testImage = [UIImage imageNamed:@"image1.png"];

// embed the image into the content view
//UIImageView *backGroundImage = [[UIImageView alloc] initWithImage:testImage];
CGRect imageFrame = CGRectMake(0,0,320,480);
UIImageView *backGroundImage = [[UIImageView alloc] initWithFrame:imageFrame];
backGroundImage.image = testImage;
[testImage drawInRect:imageFrame];
[searchViewController.view addSubview:backGroundImage];    
[backGroundImage release];


I don't think this is what you were looking for .. but hope it gives you some clues.

Sajid

Thanks!

Meanwhile I found out that at least it is possible to access the app's sandbox file system in the iPhone simulator, it is just mapped to /var/folders/.. somewhere.

So I was able to take a photo with PhotoBooth and copy it my iPhone app's sandbox and display it from there. (Just for a demo).

ernst42 Wrote:
Thanks!

Meanwhile I found out that at least it is possible to access the app's sandbox file system in the iPhone simulator, it is just mapped to /var/folders/.. somewhere.

So I was able to take a photo with PhotoBooth and copy it my iPhone app's sandbox and display it from there. (Just for a demo).


Great thanks for the tip.

Do you know how to show a Progress bar to show the progress of an uploaded file and to know when the file upload has been completed. Currently I display a Progress indicator (circular thingy) until I receive a URL response from the server.

Sajid

No sorry, I did not use a progress bar yet.

sdalvi Wrote:
Do you know how to show a Progress bar to show the progress of an uploaded file and to know when the file upload has been completed. Currently I display a Progress indicator (circular thingy) until I receive a URL response from the server.

Sajid

Hey, I tried using th following code:

Code:
-(BOOL) startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>) delegateObject
{
    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsImageEditing = YES;
    printf("%@", controller);
    [controller presentModalViewController:picker animated:YES];
    
    return YES;
}


However, I've found (through the console and debugger) that it goes into an infinite loop. Everytime this gets run:

Code:
[controller presentModalViewController:picker animated:YES];


It would call the exact same method again. over and over again. anyone know what's wrong? this is pretty frustrating.

Oops, I'm so sorry guys, but I forgot to set a variable to false, thus creating an infinite loop.

However, I'm still having trouble getting anything from the UIImagePickerController to show up on the iphone simulator. I just get a blank white screen. Do I need to do anything in Interface Builder to get it to link with my UIImagePickerController? I currently have the File Owner as my UIImagePickerController. Anybody have any other ideas?
Reference URL's