Rails Binary Stream support

后端 未结 5 1862
独厮守ぢ
独厮守ぢ 2020-12-15 21:59

I\'m going to be starting a project soon that requires support for large-ish binary files. I\'d like to use Ruby on Rails for the webapp, but I\'m concerned with the BLOB su

5条回答
  •  孤城傲影
    2020-12-15 22:23

    You can use the :binary type in your ActiveRecord migration and also constrain the maximum size:

    class BlobTest < ActiveRecord::Migration
      def self.up
        create_table :files do |t|
          t.column :file_data, :binary, :limit => 1.megabyte
        end
      end
    end
    

    ActiveRecord exposes the BLOB (or CLOB) contents as a Ruby String.

提交回复
热议问题