views:

348

answers:

1

The app that I am creating uploads images in four(the fourth is a test function) ways;

1.Directly from UIImagePickerController with UIImagePickerControllerSourceTypeCamera like this:

//didFinishPickingImage method
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
{
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}

CGRect myImageRect = CGRectMake(30.0f, 190.0f, 250.0f, 210.0f); 
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
//released in dealloc because I reuse it alot

myImage.image = img;
[self.view addSubview:myImage]; 

2.Directly picking from photo library also using

myImage.image = img;

3.Using the image saved from 1.

pathFile = @"/private/var/mobile/Media/DCIM/100APPLE/"; 
NSString *ImagePath = [pathFile stringByAppendingString:imageFileName];
NSData *imageDataFile = [NSData dataWithContentsOfFile:ImagePath];  

UIImage *img = [UIImage imageWithContentsOfFile:ImagePath];

myImage.image = img;

4.As a test function: Using an image taken with the iPhone default camera app (same as UIImagePickerController) but using ImagePath instead of UIImagepickerController, UIImagePickerControllerSourceTypePhotoLibrary.

//Same as Number 3.
pathFile = @"/private/var/mobile/Media/DCIM/100APPLE/"; 
NSString *ImagePath = [pathFile stringByAppendingString:imageFileName];
NSData *imageDataFile = [NSData dataWithContentsOfFile:ImagePath];  

UIImage *img = [UIImage imageWithContentsOfFile:ImagePath];

myImage.image = img; 

*Up to here, the user can see the file in any of the four ways on the screen added to myImage instance of UIImageView(Depending on the user selection). This proves that I am selecting the right files(for three and four).

//uploading function

NSData *imageData = UIImageJPEGRepresentation(myImage.image, 1.0);


NSMutableURLRequest *request2 = [[[NSMutableURLRequest alloc] init] autorelease];
            [request2 setURL:[NSURL URLWithString:urlString]];
            [request2 setHTTPMethod:@"POST"];

NSMutableData *body = [NSMutableData data];
//... append boundary, content-disposition code etc here.
[body appendData:[NSData dataWithData:imageData]];
[request setHTTPBody:body];

The problem is that, on upload, number 1,2 and 4 work, NUMBER 3 DOESN'T.

Console output; Program received signal: "EXC_BAD_ACCESS"

I am aware that this output stems from attempted access from released objects, and I have run into and solved this problem in other situations. But found no way here yet, even after counterchecking my memory allocations.

I would REALLY appreciate ways to solve this issue.

A: 

iPhone OS had created another folder "/private/var/mobile/Media/DCIM/101APPLE/" different from the default 100APPLE.

I realized that actually sometimes the photos are also saved in a folder 999APPLE, 102APPLE etc. This depends on how you delete, copy and create photos in the Camera Roll.

So your Camera Roll pictures could actually be stored in many different folders.

Therefore, not being able to execute [NSData dataWithContentsOfFile:ImagePath];, it throws exception:

"EXC_BAD_ACCESS"

erastusnjuki