Note: I’ve included all my console output as pastebin links to keep this question easy to read …
I’m trying to create a basic image file upload for my RoR application. But every time I submit a form with the image attached (a multipart encoded form with a single file input), I get the follow error on the WEBRick console:
I’ve searched for a while now, and several other places mention similar problems, but the only prescription I found was to upgrade rack-test due to a bug in a particular version. I can’t seem to find which version they are referencing, and I have run gem update and bundle update to no avail. Here is the output of bundle:
I’m not sure what else I can do to upgrade rack-test – I’m still very new to Rails and the Linux environment in general.
One last note: although I have tried uploading several different files of varying sizes, from 4KB to 300KB, the size of the request as seen in Firebug is always 216B. I’m not super familiar with the inner workings of a multipart file upload request, but is it possible something is wrong with my HTML form itself?
Links to similar problems:
Rails3, Cucumber, Capybara, File upload => bad content body (EOFError)?
http://groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a
It appears that the problem was not on the Rails side, but with my forms. I had been using this jQuery plugin to try and custom style the file input control. It works by placing a file input control with
opacity:0;over whatever element you provide it (in my case, my button’sdiv).I’m not sure what was happening, but the requests were being sent out from the browser with the opening boundary for the multipart data, but no body or closing boundary. In other words, FireBug showed the outbound request payload as simply:
Instead of:
Once I gave up on the custom styling and simply plugged in a normal form, it all worked fine. Hopefully this is somewhat helpful to others who might encounter similar problems!