2

我有以下文件上传器

class ItemImageUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay
  include CarrierWave::MiniMagick
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  def default_url
    asset_path("fallback/" + [version_name, "image.png"].compact.join('_'))
  end

  def cache_dir
      "uploads/tmp"
  end

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fill => [80,80]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

图片类

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
  mount_uploader :image, ItemImageUploader
  process_in_background :image
  validates_presence_of :image

  def copy
    Picture.new(:image => self.image)
  end

以及carrier_wave.rb 初始化文件中的以下配置:

CarrierWave.configure do |config|
config.enable_processing = true
    #config.permissions = 0666
    #config.directory_permissions = 0777
    config.storage = :file
end

图片已正确上传,但未创建缩略图,未发生错误。请指教。

4

2 回答 2

3

我自己就用头撞到这个。正如评论所暗示的,使用carrierwave_backgrounder会导致这个问题。您可以在他们的文档中看到它:

process_in_background -This stores the original file with no processing/versioning.

对解决方案没有帮助,但我想我会验证问题。

于 2013-04-17T22:06:02.150 回答
0

我今天为此挣扎了几个小时,因为我遇到了同样的问题。可以上传原始版本,但没有调整大小。它在本地工作,但不在我的生产机器上。希望有同样问题的人偶然发现这个答案并节省一些时间。

结果发现我的 ImageMagick 版本没有使用正确的代表构建,这是以下输出$ convert -version

Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP 
Delegates (built-in): zlib

我使用这个答案来安装代表并构建 ImageMagick 的新版本:ImageMagick missing decode delegates

之后,使用以下命令提取 ImageMagick 信息$ convert -version

Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP 
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png tiff wmf x xml zlib

现在我在滚!

于 2015-08-01T20:08:32.040 回答