如何检查是否图像版本存在的S3与Carrierwave与雾? [英] How to check if image version exists on S3 with Carrierwave and Fog?

查看:165
本文介绍了如何检查是否图像版本存在的S3与Carrierwave与雾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传我的图片与Carrierwave与雾到S3。在上传我也创建图像的缩略图:

I'm uploading my images with Carrierwave and Fog to S3. On the upload I also create a thumbnail version of the image:

version :thumb do
  process :resize_to_limit => [90, 80], if: :is_resizable?
end

现在我需要一种方法来检查,如果缩略图存在。

Now I need a method to check if thumbnail version exists.

的<一个href="http://www.rubydoc.info/github/jnicklas/carrierwave/CarrierWave/Storage/Fog/File#exists?-instance_method">Documentation列出了的存在?方法。这实际工作,如果我要检查的原始版本存在:

The Documentation lists the exists? method. This actually works, if I want to check the existence of the original version:

asset.file.exists? # => true

但是,当我用大拇指的版本是这样的:

But when I use the "thumb" version like this:

asset.url(:thumb).file.exists?

它那里得到:

it get:

未定义的方法的存在?为#&LT;字符串:0x007fcd9f9d9620&GT;

推荐答案

使用这样的:

asset.thumb.file.exists?

来代替: asset.url(:拇指)?.file.exists

这篇关于如何检查是否图像版本存在的S3与Carrierwave与雾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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