Home > OS >  Calling a function after a download request is finished
Calling a function after a download request is finished

Time:07-07

I'm currently trying to get execute this call back function after the request is finished, so I'm able to close the modal where

function handleDownloadFinished(): void{
setDownloadingActivity(false);}

I want this code to run after this:

public static async exportData(id: number, _callback: Function): Promise<void> {
const queryString = stringifyQuery(
  {
    token: BaseAPI.getJwt(),
  },
  {
    arrayFormat: "bracket",
  }
);
const anchorElement = document.createElement("a");
anchorElement.download = "file.xlsx";
anchorElement.href = `URL`;
anchorElement.click();
_callback();}

Unfortunately, It runs both functions at the same time, and then the animation does not run. Some times, I'm able to make the animation run, but not stop. Right now, to have It working, the application relies on user input to stop it running.

CodePudding user response:

The browser does not communicate the progress of downloaded files to a webpage in any way. So you code cannot know when a download has finished.

You're just going to have to design your UI with this fact in mind.

  • Related