Bulletproof function for file downloading from JavaScript.