Requesting to prepare a file and return path, allow user to download when ready

Scenario & Problem description :

  1. User request file to server
  2. File is big so it takes time to generate
  3. Client side a spinner is running to show that we are making file.
  4. After few mintes, their proxy times out because server hasn't respond to the query (The reason file is too big to generate)

My Understanding :

After looking deep into this situation, I have figured that client's proxy is timing out and I have no control over it. The only thing I can do is to change the logic of client requesting and downloding a file.

Solutions that I thought about :

Solution 1 :

  1. User requests file
  2. Server creates a temporary file on server side, and create an http path such as

    http:\www.mydomain.com\temp\download\files\12342323.pdf

  3. The link gets deleivered to client faster but it remains inactive for certain duration.
  4. User clicks on link once it's activated.

Solution 2:

I havn't much read about this, but Is it possible to create socket connection via node.js and transfer the file?

Note:

In solution 1 is top of my head, without any coffee from last 4 hours. The only thing I am stuck as in knowledge is. How am I going to detect that file is done on server side and now my ajax script can enable the link, or download it.

Please throw some new idea to handle this situation. NO DIRECT ANSWER REQUIRED. I rather know which equipment to use for fishing, then getting a fish readymade. :) Cheers.

FYI : I have php and javascript as a tool to use at the moment.

If the file always gets created eventually, and the problem is on the client side, you could do the following:

  1. When the user clicks on download, you start generating the file via AJAX, and store the name in a session variable for example
  2. In the client, the most simple solution would be to poll the server every X seconds, and have it simply check if the file exists (via php), to know if it has been already created
  3. Once it is, redirect user with javascript to the file's location to make it download.

Then you could setup a cron job or something like that to delete the files that have already been downloaded.

Add the criteria to generate the file to a queue, then redirect user to another page. Then have a process running every minute or so that reads from the queue and generates the file. Once the file is created email the link to the user.

We`ve done it with timeout request, because we didn't need a whole push server. So how it works.

You creating a link and a checker link. Then you starting to sending requests to checker link, that gives you a state of file. For me 10 second was enough. On server side you creating a queue and when it`s done it writes the flag, where you checker url says about success geeration and gives client a url redirect to file. That's it.

If your time limit is small and you want to say client that file ready as faster as possible you can create a socket connection. And than just push request to client.