pyramation
pyramation

Reputation: 1671

paperclip process file contents before upload

I want to compute a hash before uploading a file so that no duplicates are stored on the server.

Using the paperclip gem, what's the best approach to do processing on a file before saving it or inserting data in the database?

Upvotes: 0

Views: 773

Answers (1)

sorens
sorens

Reputation: 5060

ActiveModel has a callback before_create (among others) which would make an ideal place for you compute something before the record is created. For a full list of the callbacks available, see the Ruby on Rails Guides: Active Record Validations and Callbacks.

class Asset
  has_attached_file :image
  before_create :do_something
  def do_something
  end
end

Upvotes: 2

Related Questions