0

is there such way/method/strategy to detect if the downloading of a file is finished?..my problem is like this.

Scenario: when click the report generator button, a loading wheel icon appears because it takes a while to generate the spreadsheet...and now, when the download has finished and the spreadsheet was saved in the client's machine, the loading wheel icon is still there spinning.. the only way that I think of to remove that spinning wheel is by detecting if the downloading is finished and then hide the spinning wheel ..so how ? :confused:

PLEASE TAKE NOTE BEFORE MARKING MY QUESTION AS DUPLICATE: when i push the button, I am writing a file in the spreadsheet before it automatically/forcefully gets downloaded. it's not like the typical downloading of a static file

sasori
  • 5,249
  • 16
  • 86
  • 138
  • 2
    When the user requests the download, why would you still have a spinning wheel? The presence of a spinning wheel indicates to the user that there is still something to be done, but the download is the final step. –  Sep 07 '13 at 15:24
  • 1
    The browser has its own download manager that tells the user when the download is done. You don't need to do it yourself. – Barmar Sep 07 '13 at 15:24
  • Try look [here](http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download) – Shahar Galukman Sep 07 '13 at 15:25
  • @remyabel It's because I am pulling data from database and it's quite huge, and then write it in spreadsheet..when I click the report generate button, it the spinning wheel appears, coz it takes 5 to 10 minutes to finish the report generation and automatically spit out the window to save the file generated – sasori Sep 07 '13 at 15:29
  • 1
    May be you can hide the icon using javascript just before the window pops up. – Binu Pandian Sep 07 '13 at 15:42
  • how ? can you tell how to detect when the window pops up ? – sasori Sep 07 '13 at 15:43

2 Answers2

1

This type of long running processes are not well suited for the typical web request / response workflow. Yes, it will work...but I believe there are issues and the user experience is not ideal. I better workflow would be to do one of the following:

  1. Cache the report. If the data in the report can be stale for a period (e.g. 1 day) then setup a cron to generate the report and then return the cached report to the user. The user experience will be an immediate download.

  2. If the report needs to be generated on the fly, then have the user request the report and return a result immediately. Later deliver the report via a notification system (assumes they have a dashboard or something on your site) or email (the must provide you an email address when requesting the report).

I think that these two options provide a better user experience.

rcravens
  • 8,320
  • 2
  • 33
  • 26
  • the 2nd option has something..the "on the fly" ..this report generation thing is located at the admin dashboard, it cannot be delayed..they want the spreadsheet immediately when they pushed the generate report button, it's ok for them to wait 5 to 10 minutes ..any other ideas?...how to detect before the window pops up ? as @Binu Pandian mentioned in his reply in the first thread – sasori Sep 07 '13 at 15:47
  • I have found that requirements like "It cannot be delayed...they want the spreadsheet immediately" can usually be vetted a bit more. For example, the two cases above trade accuracy (up-to-date data) for timeliness (speed of delivery). Option one caches the data. Do your users really need this report generated with every request? If that requirement is relaxed, you will have an easier system to build. Generating the report sounds resource heavy on the server. How many admins will access this concurrently? Some engineering choices to make...enjoy. – rcravens Sep 08 '13 at 14:18
  • i'll choose this as the best answer though it didn't helped my problem at all,maybe in a different project it will help. – sasori Sep 08 '13 at 14:30
0

I agree with rcravens answer but would add the following to option 2: By clicking on your »Download« button, you invoke the generation of your spreadsheet on the server and store it in an temp dir. Via AJAX (preferably webworkers) you inform your user that the generation is in progress and constantly check the status of the file. While checking and returning false, show your wheel. If the generation is complete, stop the wheel and invoke the download via JavaScript.

If you can, the experience would be even better if you’d show the user a progress bar of your spreadsheet-generation, so he knows why and how long he’s waiting.

Hope that helps.

max
  • 1,509
  • 1
  • 19
  • 24