【问题标题】:Carrierwave/Fog - Argument error, provider not recognizedCarrierwave/Fog - 参数错误,提供商无法识别
【发布时间】:2011-07-27 05:39:11
【问题描述】:

我正在使用 Carrierwave 0.5.3 和 Fog 将图像上传到 Amazon-S3。

设置在本地运行时运行顺利,没有错误。

但在 Heroku 上运行时,上传失败并显示以下消息:

2011-03-31T12:53:46-07:00 app[web.1]: ArgumentError ( is not a recognized storage provider):
2011-03-31T12:53:46-07:00 app[web.1]:   app/controllers/useditems_controller.rb:36:in `create'

我有一个初始化器:

# /config/initializers/fog.rb
CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'secret',
    :aws_secret_access_key  => 'also secret',
    :region                 => 'eu-west-1'
  }
  config.fog_directory  = 'jabberwocky'
end

还有一个上传者:

# /app/uploaders/image_uploader.rb
# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or ImageScience support:
  include CarrierWave::RMagick

  # Choose what kind of storage to use for this uploader:
  storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "useditems"
  end

  def cache_dir
    "#{Rails.root}/tmp/uploads"
  end

  # Create different versions of your uploaded files:
  version :thumb do
     process :resize_to_limit => [220, 2000]
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    %w(jpg jpeg gif png)
  end

end

我已经追踪到 Fog 的错误消息,似乎 Heroku 下的 Fog 没有从初始化程序中获取配置信息。 :provider 不知何故为空。但我不知道如何解决它。

任何帮助将不胜感激。

我正在使用:

rails 3.0.4
heroku 1.19.1
fog 0.7.1
ruby 1.9.2 under rvm

【问题讨论】:

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


    【解决方案1】:

    错误是由于我错误地将初始化程序添加到 .gitignore 文件。因此,它从未上传到 Heroku。

    【讨论】:

      【解决方案2】:

      为了完整性添加这个...

      在收到此错误消息后,我的头撞在墙上几个小时后,我发现在载波初始化程序的开头有这行:

      if Rails.env.test?
        ...
      

      所以初始化器只在测试环境中被考虑。删除它后,一切都按预期工作。

      【讨论】:

        猜你喜欢
        • 2013-04-13
        • 2018-11-23
        • 1970-01-01
        • 1970-01-01
        • 2013-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多