Chris R. wrote:
Im uploading a file to my rails app, i’s usually a large file, 5-50mb.
Once the file has been uploaded it must be parsed and processed, this
can take a very long time, 1-20mins. The problem is that most of the
time my browser timeouts.
Im not really sure how to solve it. One idea is that i have a script
run constantly on the server that checks for uploaded files in a
specified folder. This would prevent timeouts. The user would simply
upload the file and be shown a screen telling them that the data will be
in the system in 1-20 mins.
Im not sure if this is an ideal solution though. What are your
thoughts? Does anyone have experience with this or have better
After the browser uploads the file trigger a background process with an
ajax call. This then at various points in this long running process
update a session variable with the progress on your long action:
session[:progress] = 0.1
session[:progress] = 0.2
Then have a periodic AJAX call to retrieve a progress bar partial based
on the session[:progress]
Progress: <%= (session[:progress] * 100).to_i %>%
I have used this technique with an action that uploads some large chunks
of data to external ftp servers, runs about 10-30 minutes. The ajax
keeps the browser from getting bored. Note this will not work in
webrick. It require a minimum of 2 server processes and Webrick only
uses 1. You need one proc to do the long running action, and one proc
to respond to the ajax queries.
You might even be able to do the same thing with the uploading of the
file itself as well, but I haven’t actually pulled that one off. Check
out the file_upload_progress plugin (i think thats whats its called) for
more info on ajaxy uploads.