Refactor file upload checking code