Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 lib
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 paperclip_database_storage.gemspec
README.md

paperclip_database_storage

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

Requirements

paperclip_database_storage requires Paperclip version >= 3.2.0.

Installation

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://github.com/gokuu/paperclip_database_storage.git'

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

  rake paperclip_database_storage:setup

Usage

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"
end

Remarks

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.

Limitations

  • 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.

TO-DO

  • 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.