In my app where I need similar thing (just with json file), I have one button which sends request to the server to gather the needed data. When the data is received from server I display another button like this:
Download your data!
The link utilizes the download attribute while encoding the data in the
href attribute. As a result once the user clicks the link they will be prompted to download a file with the data that was set it.
I’m sure this can be easily adapted for any other types of files.
Hope this helps.