2
votes

I am storing a video file of size more than 1 GB and storing into homeDirectory. I am trying to convert into NSData object as follows

NSData *videoData = [[NSData alloc] initWithContentsOfFile:filePath];

but here I am getting video data as nil. When I tried for video of 500 MB it is working fine.

Is there any limitation on size while converting into NSData?

1

1 Answers

8
votes

Try using this (requires iOS 5.0 or later):

NSError *error = nil;
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath
                                              options:NSDataReadingMappedIfSafe
                                                error:&error];

Prior to iOS 5.0 you can use:

NSData *data = [[NSData alloc] initWithContentsOfMappedFile:filePath];

These will map the file into virtual memory if it is safe, which will significantly reduce the amount of memory used overall.