paperclip process file contents before upload
I want to compute a hash before uploading a f开发者_开发知识库ile 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?
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
精彩评论