开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜