Validate file before download

I managed to make a function that downloads a file. I’m a bit worried now about the security of the app and possible errors of not supported files (That file will be used later on, on another function).

How can I make sure that the file will be downloaded is nothing else than an ical file. I know I can validate the extension but, what if that file is let’s say an executable file that has been renamed and it will harm the devices? Is there any API that scans files for harmful code? or anything?