sagarkothari
sagarkothari

Reputation: 24810

store file in NSDocumentDirectory of iPhone

I am using a UIImagePickerController in my application.

After selecting an image by user,

image should be saved at application Documents Directory,

my Code is Give Below.

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
     [picker dismissModalViewControllerAnimated:YES];
     NSData *imgData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);
     UIImage *img = [[UIImage alloc] initWithData:imgData];
     stuImgView.image = img;
     [img release];

     //write image
     NSString *imageFilename = [NSString stringWithFormat:@"%i.jpg", currentStudent.stuNo];
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *path = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0], imageFilename];
     UIImage *stuImg; 
     BOOL success; 
     NSFileManager *fm=[NSFileManager defaultManager];
     // how to store file at documents dir????
}

i dont know how to use file manager to store a file?

Help me Out.

Thanks in advance.

Upvotes: 3

Views: 7449

Answers (1)

notnoop
notnoop

Reputation: 59299

You can use writeToFile:atomically::

[imgData writeToFile:path atomically:NO];

Upvotes: 4

Related Questions