title: Rails: How to stream data to and from a binary column (blob)
body: <p>I have a question about how to efficiently store and retrieve large amounts of data to and from a blob column (data_type :binary).  Most examples and code out there show simple assignments but that cannot be efficient for large amounts of data.  For instance storing data from a file may be something like this:</p>
  
  <pre><code># assume a model MyFileStore has a column blob_content :binary
  
  my_db_rec = MyFileStore.new
  File.open("#{Rails.root}/test/fixtures/alargefile.txt", "rb") do |f|
    my_db_rec.blob_content = f.read
  end
  my_db_rec.save
  </code></pre>
  
  <p>Clearly this would read the entire file content into memory before saving it to the database.  This cannot be the only way you can save blobs. For instance, in Java and in .Net there are ways to stream to and from a blob column so you are not pulling every thing into memory (see Similar Questions to the right).  Is there something similar in rails?  Or are we limited to only small chunks of data being stored in blobs when it comes to Rails applications. </p>