That sounds like the FileDocument (or specialisation of FileDocument) object you are using doesn't have the Name attribute set for some of the images.
It may be worth setting a breakpoint or a Log Message just before any Download File action you have to record what the value of this field is. It would confirm if it really does have a Name or not.
Good luck!