Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell paperclip to not save the original file?

How do I tell Paperclip not to save the original file when it is uploaded? Or even better, to store a scaled version of the file as the original?

like image 992
Jade Avatar asked Jul 10 '10 15:07

Jade


2 Answers

I believe that you can simply define a style for :original to have paperclip replace the original with that size.

:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "115x70#", :jcrop => true}, ...}
like image 84
Chris G. Avatar answered Nov 04 '22 12:11

Chris G.


Cris G's solution may be nice at most simple cases but it has limitations. consider that: style :original Paperclip process first of all others, so after that updated :original image (much smaller now) will be the source for following processing. Hence you are forced to keep :original style as best-resolutioned. The situation comes worse as you need to crop images with processor: that is the situation where you really need for real original quality. )

So I would recommend you somewhat raw (need to find out how to get every attachments of the model) solution:

after_save :reprocess_attach

private

def reprocess_attach
    if self.<atch_name>.present? && Pathname.new(self.<atch_name>.path).exist?
        self.<atch_name>.save
        File.unlink(self.<atch_name>.path)
    end
end

it doesn't care about what processing was behind the stage. It just kills original file )

like image 20
Roaring Stones Avatar answered Nov 04 '22 12:11

Roaring Stones