0

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.

Shakthi
  • 131
  • 2
  • 15

1 Answers1

1

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
dimakura
  • 7,575
  • 17
  • 36
  • thanks dimakura for the answer. If I am trying model.attachment.reproces! in production does it create temporary files and if so will the files occupy considerable memory on the server – Shakthi Sep 15 '15 at 06:57
  • I'm not sure. If it's a concern, you can try it for first 100 models, then for 1000 and compare CPU and memory usage. Then process with more big-scale updates. – dimakura Sep 15 '15 at 06:58