简体   繁体   English

Rails和Paperclip ...不保存原始图像,只保存样式?

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

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! 干杯!

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 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 以下是来自同一作者的有效内容: https//gist.github.com/tekn0t/755593

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM