[LRUG] AJAX file uploads and content types

Andrew Stewart boss at airbladesoftware.com
Wed Apr 4 01:29:12 PDT 2012

Morning El Rug,

I have a Rails 3.0.11 app which does AJAX file uploads using the remotipart gem [1].  Everything works perfectly in development.

In production I get 406 errors.  I'd like to (a) find and fix the problem, and (b) work around it in the meantime.

The basic process is this:

1) User submits a 'remote' form with a file input.
2) Remotipart's javascript intercepts the form submission, creates an iframe with the form data in it, and posts the iframe's form to the server (with content type text/html).
3) A remotipart middleware intervenes in the request to convert the request to text/javascript.
4) My controller action saves the image and responds by rendering create.js.erb.

The problem seems to be at step 3.  To gather more information I added `$stderr.puts "useful info"` etc to the remotipart middleware but I can't find the output in my unicorn logs.

The 406 error is thrown at step 4 because my controller action only responds to javascript but the request is arriving as HTML.

Can anyone shed any light on this?

And in the meantime, can anyone tell me how to render my create.js.erb response even if the request wants html?  I have tried various permutations in my respond_to block without success.

Thank you!

[1] https://github.com/JangoSteve/remotipart
[2] https://github.com/JangoSteve/remotipart/blob/master/lib/remotipart/middleware.rb


Andy Stewart

More information about the Chat mailing list