How to check if image version exists on S3 with Carrierwave and Fog?

亡梦爱人 提交于 2019-12-06 20:06:13

问题


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.

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:

undefined method 'exists?' for #<String:0x007fcd9f9d9620>:


回答1:


Use this:

asset.thumb.file.exists?

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




回答2:


The correct answer is:

asset.file.thumb.file.exists?

where file = mounted_uploader and asset = model



来源:https://stackoverflow.com/questions/23578438/how-to-check-if-image-version-exists-on-s3-with-carrierwave-and-fog

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