Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing a progress bar when downloading a file from the server

I need to show a progress bar to the user who requests a file to download. I am using J2EE application to generate the file. User will submit the form data to get the file. The server takes all the submitted data manipulates, generates and sends a PDF file back to Client.

So I want to show a progress bar to the user till the file comes to the Client side. Is there any way to do this ?

like image 827
Puru Avatar asked Jun 10 '10 05:06

Puru


1 Answers

progress bar for server side file generation:

We assume that the server needs many seconds to generate the file. This event is triggered by the original request, a blocking operation. When this finishes the file will have been generated and it'll be dispatched back to the client.

At the same time you want, via other requests (ajax), to be calling the server and getting a percentage back for the file which is currently being generated for the particular user.

The glue parts here are:

  • when the original request is generating the file it needs to store the progress in frequent intervals (i.e every 10%). Storing this data in the http session will work OK.
  • the other requests (ajax) simply need to be able to pull this information out of the http session
  • synchronizing (serializing access) on the http session, something that some web apps commonly do, is out of the question, since the other requests (ajax) would simply block until the original request finished
  • on the client side it's all html+javascript to provide the interaction you need (animated progress bar). Even if the intervals are very rough (jumping from 10% to 20% to 30%) you can animate the bar with jQuery. I've done it once in the past and it looks great.

progress bar for file download:

it's best to leave this to the browser's native dialog.

like image 115
cherouvim Avatar answered Oct 13 '22 01:10

cherouvim