Like most people, I find the file upload process very annoying, in
that you hit submit and sit there, seemingly forever, as your file
gets sent. So I felt it would be a great goodness to have progress
updates as file_upload_progress offers. However, I have been unable
to get it to work, and I''m not sure why.
I created the form roughly as said, except that my target is
creations/create instead of the one in the documentation. I changed
the file_path in the configuration file to creations/create, and sure
enough, the form started spitting out requests for
''files/progress'',
providing lots of not found errors but also apparently inspiring a
response from the server. However, the client never updated progress
from 0%.
I took a look at the server and put some diagnostics in and was able
to determine that the server was properly intercepting the request
and coming up with a steadily decreasing number, which looked
suspiciously like the remaining number of bytes left to upload.
Here''s the routine I changed:
private
def upload_notify(action, params, *args)
system("echo path info comparison worked! >>/tmp/test")
upload_id = Mongrel::HttpRequest.query_parse(params
[''QUERY_STRING''])[''upload_id'']
system("echo Upload id #{ upload_id } found >>/tmp/test")
if params[Mongrel::Const::REQUEST_METHOD] == ''POST''
&& upload_id
system("echo a response was returned action #{ action } args #
{ args } >>/tmp/test"\
)
Mongrel::Uploads.instance.send(action, upload_id, *args) if
upload_id
end
end
Here are the last few lines of the output:
a response was returned action mark args 24576
path info comparison worked!
Upload id 1158534572 found
a response was returned action mark args 20480
path info comparison worked!
Upload id 1158534572 found
a response was returned action mark args 16384
path info comparison worked!
Upload id 1158534572 found
path info being compared /files/progress
a response was returned action mark args 12288
path info comparison worked!
Upload id 1158534572 found
a response was returned action mark args 8192
path info comparison worked!
Upload id 1158534572 found
a response was returned action mark args 4096
path info comparison worked!
Upload id 1158534572 found
a response was returned action mark args 0
path info comparison worked!
Upload id 1158534572 found
So it looks like it is successfully tracking the upload of the file.
But how is it being sent back to the client? The /files/progress
calls appear to be correctly running this routine but then continuing
to move forward in the rails system to cause the no route error. I
have about a million of these in the development log:
Processing Base#index (for 127.0.0.1 at 2006-09-17 19:16:59) [POST]
Session ID: 126d2f8aeac54478f881174bae52c844
Parameters: {"upload_id"=>"1158534572"}
ActionController::RoutingError (Recognition failed for "/files/
progress"):
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.4/lib/
action_controller/routing.rb:526:in `recognition_failed''
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.4/lib/
action_controller/routing.rb:516:in `recognize!''
So why would the routine correctly calculate the progress and then
continue through to error out?
I looked at the JavaScript and this also confuses me since I see the
call to a new Ajax object, which works to send the request, but not
how the request is linked to the processing code. And indeed when I
added alert() to the processing code, I never saw anything happen:
update: function(total, current) {
alert("We actually are updating! Total " + total + " / " +
current);
if(!this.uploading) return;
var status = current / total;
var statusHTML = status.toPercentage();
$(''results'').innerHTML = statusHTML + "<br
/><small>" +
current.toHumanSize() + '' of '' + total.toHumanSize() + "
uploaded.</
small>";
this.StatusBar.update(status, statusHTML);
},
I didn''t get any JavaScript errors so I have to assume that it is not
trying to update when it returns. I would expect error messages if
it was receiving the errors from the server.
I''m at my wit''s end on this one, largely because of huge gaps
in my
knowledge of how JavaScript and Mongrel work. Can someone give me a
pointer or two towards a resolution?
Many thanks for any help you can give.
D