Handling file processing + downloads

Say you have a page with a file download, but that download requires some process to run to generate the download, say this takes around a minute to generate, how do you show this?

If you use just a regular link, the end-user will click that link and nothing will seem to happen, so they click it again, and again, you end up with several processor intesive tasks stacking up on your server and an angry end-user. This is no good.

I came accross this problem a while back and in my case, an additional problem I had was that I had no way to 'listen' to see when the file had been processed. I was working on a Java project and the processing system was called via a simple servlet, there was no way to tell what was happening, all I knew was that at some point in the future a file would become available to download.

The solution it turned out was quite simple, when the 'download' button was clicked, the servlet was sent off to start processing the file and the UI was updated with a 'loading' message. Using Javascript, the browser would then start looking for the presence of a specific cookie every 200ms or so. Once the servlet had done it's job it set this cookie with a 1 second lifetime. The javascript then picked up the presence of that cookie and could update the UI accordingly and start the download, simple.