Domanda

I am using Ruby, or more specifically the Ramaze framework with the Sequel ORM. So please don't tell me about the Paperclip gem, as it is only compatible with ActiveRecord.

With that in mind, how can I store an image in a database using Ruby and Sequel?

È stato utile?

Soluzione

require "sequel"

DB = Sequel.sqlite

DB.create_table :images do
  primary_key :id
  String :name
  File :data
end

images = DB[:images]
images.insert(name: 'foo', data: Sequel.blob(File.read('/mydir/myimage.jpg')))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top