【问题标题】:How to check if image version exists on S3 with Carrierwave and Fog?如何使用 Carrierwave 和 Fog 检查 S3 上是否存在图像版本?
【发布时间】:2014-06-28 00:14:02
【问题描述】:

我正在将使用 Carrierwave 和 Fog 的图像上传到 S3。在上传时,我还创建了图像的缩略图版本:

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

现在我需要一个方法来检查缩略图版本是否存在。

Documentation 列出了exists? 方法。如果我想检查原始版本的存在,这实际上有效:

asset.file.exists? # => true

但是当我像这样使用“拇指”版本时:

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

得到:

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

【问题讨论】:

    标签: ruby-on-rails amazon-s3 carrierwave fog


    【解决方案1】:

    使用这个:

    asset.thumb.file.exists?
    

    而不是:asset.url(:thumb).file.exists?

    【讨论】:

    【解决方案2】:

    正确答案是:

    asset.file.thumb.file.exists?
    

    其中文件 =mounted_uploader 和资产 = 模型

    【讨论】:

    • 如果此代码解决了问题,您应该添加一些文本来解释每个部分的作用。这样,您可以帮助将来遇到类似问题的人。此外,您的回答更有可能获得投票。
    猜你喜欢
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 2013-08-25
    • 2016-06-29
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多