Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Adds support for storing a paperclip attachment file contents in a database table


Adds support for storing a paperclip attachment file contents in a database table.


paperclip_database_storage requires Paperclip version >= 3.2.0.


paperclip_database_storage is distributed as a gem, and that is how it should be used in your app.

Include the gem in your Gemfile, from rubygems:

  gem 'paperclip_database_storage', '>= 3.2.0'

Or, get the master branch from the repository:

  gem 'paperclip_database_storage', :git => 'git://'

And afterwards, run the task to create the necessary migrations:

  rake paperclip_database_storage:setup


All you need to do is, when defining a Paperclip attachment, set its :storage option as :database:

class MyModel < ActiveRecord::Base
  has_attached_file :attachment,
    :storage => :database,
    :styles => {
      :medium => "300x300>",
      :thumb => "100x100>"
    :url => "/:class/:attachment/:id/:style/:basename.:extension"


The migration defined by paperclip_database_storage contains several indexes, as every possible combination of the fields that can identify a single attachment. This should help getting an attachment as quickly as possible using any combination of parameters. As of version 3.0.7, the attachments are stored encoded in base64, to prevent loss of information. All previous stored attachments will still be usable as the table has a new field to indicate whether the attachment is stored base64-encoded.


  • Paperclip-database currently only supports one database attachment per model.
  • Although you can define a custom :url option for getting the attachment, make sure you define one that uniquelly identifies each attachment, otherwise the plugin will raise an Exception.


  • Add tests!
  • Add support for more than one database attachment per model
  • Enable defining a separate table for each different attachment

Copyright (c) 2012 Pedro Rodrigues, released under the MIT license

Something went wrong with that request. Please try again.