lostintranslation
lostintranslation

Reputation: 24583

Export/download dynamic file w/ status on client

I have an angularjs application that has an export feature. Export generates a file dynamically server side. The generation of this file could be seconds to minutes. I would like to be able to give the user some sort of status that the server is generating the file. Even if its just a spinner on the page letting the user know something is happening.

My problem however is this. I am not making a 'GET' request as a resource in angular. I am just setting:

window.location.href

to point at the url on the server that will start the file generation an send it back to the client.

This means that if the file takes 1 minute to generate the download dialog for the browser does not pop up until that minute passes and the file is ready to download.

Is there a way to make a GET request for file download and then get a callback when the get request was successful?

Upvotes: 0

Views: 144

Answers (1)

Prasad K - Google
Prasad K - Google

Reputation: 2584

You can initiate downloading the file in an hidden iframe and show a loader, and hide the loader when iframe is loaded using onload event handler.

Sample code below just to give you an idea -

hiddenIframe.src = url;
loader.show();

hiddenIframe.onload = function() {
   loader.hide();
};

Upvotes: 1

Related Questions