views:

331

answers:

1

hi.

I have a multiple file upload form(html5) and want to update my view as soon one of the images is transfered to my image server.

Currently I upload the files with ajax and use response_to_parent to update my upload view when all images are transfered to the image server.

Is it possible to call a Javascript function from the controller more than once per action?

def upload
  params[:images].each do |file|
    upload_to_image_server(file)
    #page << Update upload View
  end
end

Thanks, Michael

A: 

AFAIK, this is not possible [without extraordinarily hacking into response sockets]. However, there are some alternatives to that.

You can try using uploadify (untested), or some comet-like alternative. Another alternative is to use push trough web sockets. Pusherapp seems to do the trick (you can call Pusher#trigger several times in a request). Not sure about all-browser compatibility, though.

In general, is better to have quick response controllers, so perhaps tweaking the ajax (or flash) for the image upload to upload one file at a time would be a better approach if you are worried about notifying the user about upload progress.

Chubas