What do you mean by "but it fails...because the length of the file is too big"? Does it die and do nothing? Do you get an error message and if so, what - EXACTLY - does it say? Does it do something else, and if so, what?
How do you know that is it failing because the file is too big?
You need to tell the details if you want any kind of reasonable help.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors