I am not able to access the image stored in the document directory...

Discussion in 'iOS Programming' started by gowdalokeshs, Oct 20, 2010.

  1. gowdalokeshs macrumors member

    Joined:
    Aug 31, 2010
    Location:
    bangalore
    #1
    I am developing an app, where i am accessing the saved photoalbum of iphone.
    After accessing i am storing the same in the documents directory.
    Now when i try to access the image from document directory, i am getting the null image....
    I think the way i am storing the image is not proper.
    I am attaching the code for your reference....Pls help....

    Code:
    #pragma mark -
    #pragma mark imagepicker delegate method
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {
    	
    	[picker dismissModalViewControllerAnimated:YES];
        self.cameraAlbumPicker.view.hidden = YES;
    	self.imgViewDisplayImage.hidden = NO;
    
    	NSData *imageData=[NSData dataWithData:UIImagePNGRepresentation(image)];
    	UIImage *img=[[UIImage alloc] initWithData:imageData];
    	self.imgViewDisplayImage.image = img;
    	[img release];
    	
    	NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    	NSString *directoryPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"User Image"];
    	NSString *filePath=[directoryPath stringByAppendingPathComponent:@"image.png"];
    	[imageData writeToFile:filePath atomically:YES];
    	NSLog(@"filePath:%@",filePath);
    	
    }
    


    I am accessing the image like this:

    Code:
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    	NSString *directoryPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"User Image"];
    	NSString *filePath=[directoryPath stringByAppendingPathComponent:@"image.png"];
    
    	while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    		NSLog(@"File exists");
    		UIImage *image = [UIImage imageWithContentsOfFile:filePath]; 
    	}
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Apply basic debugging skills.

    Confirm that everything else before reading the file works.

    Is the image being written to the file?
    How would you test this?
    What does NSData's writeToFile methods return?

    If the image isn't being written to the file, why not?
    Does the pathname exist?
    Do all directories leading to the file exist?
    If not, what should you do to create them?

    If the image is being written to the file, is it the right size?
    It should be identical to the original image-file it was copied from, right?
    Does the file contain the right data?
    Again, it should be identical to the original.

    If the file exists, why are you looping with a 'while' statement?
    Are you expecting a file to disappear by itself?
    What will happen if the file exists?
    What purpose does an infinite loop serve?
     
  3. gowdalokeshs thread starter macrumors member

    Joined:
    Aug 31, 2010
    Location:
    bangalore
    #3
    Can you please tell me how to check this directory ?

    My image is getting stored in this file path. How can i check this directory ?


    /var/mobile/Applications/DDE8A6D1-4569-4D06-9891-C22B15FF282C/Documents
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Open the Finder. Use the Go->Go to Folder... menu item
     

Share This Page