1. Make a new rails app:
rails new bonehead
2. Rename /public/index.html to /public/old_index.html
3. Stick the following version of index.html in its place:
4. Now, we’ll need a controller:
rails g controller Bounces incoming
5. then fiddle /config/routes.rb
from: get “bounces/incoming/”
to: post “bounces/incoming/”
6. Then edit your bounces_controller.rb so it looks like this:
Now, you have a “looks like it’s working” version of a file uploader to play with. It doesn’t save anything, which is perfect at this point. You can’t hurt anything because it doesn’t do anything. Have a good play with it. Here are some things to notice:
A. When HTML5 file inputs are set to “multiple,” they make a FileList object. Check it out in the console (Firefox with Firebug extension works fine.) There are lots of attributes in there, but these seem to be the most important
B. HTML5 doesn’t provide some of the data we like to get about files in the request, so we send it in custom headers. “X-File-Name” seems to be common practice for the file name, and ‘X-Query-Params’ seems to be common practice for other parameters in JSON-encoded form.
C. I added a couple of attributes to the JSON hash that might come in handy:
a ‘file_model’ attribute so I can say this gets attached to an ‘avatar’ model or an ‘uploads’ model or whatever.
a ‘file_model_id’ so I can say that this file gets attached to some particular instance of the model.
D. The bounces_controller just sends a response — It could be a lot more compliant, but this tells us what’s going on.
Next, I’ll start saving the files using Paperclip.