Shakthi
Shakthi

Reputation: 141

How to update attachment using paperclip

I used paperclip to upload images to S3,

has_attached_file :attachment,
                      styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>',larger: '860x1280>' },
                      default_style: :product
validates_attachment :attachment,
      :presence => true,
      :content_type => { :content_type => %w(image/jpeg image/jpg image/png image/gif) }

Now , I want to compress the images which are already uploaded to S3 using gem "paperclip-compression", so I added processors: [:thumbnail, :compression], How would I update all the attachments using a ruby script??. I am able to read and store image into file but unable to update the attachment with the file.

Upvotes: 0

Views: 1618

Answers (1)

dimakura
dimakura

Reputation: 7655

According to paperclip wiki you should use reprocess! method:

Model.each do |model|
  model.attachment.reprocess!
end

Another option is to use rake task:

# only thumbnails style
rake paperclip:refresh:thumbnails CLASS=Model

# or all styles
rake paperclip:refresh CLASS=Model

# only missing styles
rake paperclip:refresh:missing_styles

Upvotes: 1

Related Questions