Rails和Paperclip ...不保存原始图像,只保存样式? [英] Rails and Paperclip... don't save the original image, just the styles?

查看:161
本文介绍了Rails和Paperclip ...不保存原始图像,只保存样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回形针中保存具有大量样式和大小的图像时,它还会保存原始图像。

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.

干杯!

推荐答案

这对我有用

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

取自此处: http://tekn0t.net/delete-original-image-when-using-papercliprai

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

修改:提供的链接不再有效。以下是同一作者的有效内容: https://gist.github.com/tekn0t/755593

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

这篇关于Rails和Paperclip ...不保存原始图像,只保存样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆