Topic: Saving request.body to the DB as a file using HTML5/AJAX uploading

I've been diving into using drag and drop file uploading with HTML5.  While no expert at it, I've gotten to the point where I can submit filenames to my Rails app.  However, the items submitted are just filenames.  I have to somehow read the body.request and parse that out into the proper file items to save in the DB.

Traditionally, I would do something like:

# view
<%= form_for @attachment, :html => { :multipart => true } do |f| %>
  <%= f.file_field :file %>
<% end %>

# controller
def create
  @attachment =[:attachment])!
  #...skipping validation/flash/redirections; just trying to save in DB

# attachment.rb model
def file=(data)
  self.content_type = data.original_filename
  self.binary_data =
  self.filename = data.original_filename

However, HTML5 drag and drop (or any AJAX form that submits multiple files, as far as I can tell) does not post an actual file to the server (as in an object with attributes original_filename, content_type, etc).  It just posts the filename as a string.

I've spent hours reading about this and I understand I somehow need to do something like "", but I'm not sure what exactly that is.

One example I saw was creating a TMP file and writing to it.  I got that part working and I uploaded a file via AJAX and it actually created the TMP file.

However, that created the submitted file on the file system and I need to save the file in the DB.  Not being used to diving in this deep to things, I'm really trying to understand what's going on and how I read the data into the DB given a string filename from my ajax form.

If anyone has any thoughts on this, I would greatly appreciate them.  I feel I'm really close to getting it functioning but I just can seem to get it working.