Rails and Paperclip… don't save the original image, just the styles?

陌路散爱 提交于 2019-12-09 03:36:29

问题


In paperclip when you save an image with lots of style and sizes it also saves the original.

But in my app it's not necessary to save the original, just the style will do, what I was wondering was how do you not save the original. Just store it in memory or in a temporary area and then not save it once the style have been generated.

Ideally it would not save original at all. I guess one solution would be to save the original, process the style and delete afterwards, however I'm trying to save on bandwidth and deleting the original after it has been saved kindof defeats the point.

Cheers!


回答1:


This worked for me

def destroy_original
  File.unlink(self.photo.path)
end

Taken from here: http://tekn0t.net/delete-original-image-when-using-papercliprai

Edit: the provided link is no longer valid. Here is a valid one from the same author: https://gist.github.com/tekn0t/755593




回答2:


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



来源:https://stackoverflow.com/questions/4771615/rails-and-paperclip-dont-save-the-original-image-just-the-styles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!