Carrierwave/Fog - 参数错误,提供商无法识别

发布于 2024-10-28 00:34:23 字数 1818 浏览 4 评论 0原文

我正在使用 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'

I've got aninitializer:

# /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

And an uploader:

# /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

I've Traced the error message to Fog, and似乎在 Heroku 下的 Fog 没有从以下位置获取配置信息初始化程序。 :provider 不知何故是空的。但我对如何解决它感到困惑。

任何帮助将不胜感激。

我正在使用:

rails 3.0.4
heroku 1.19.1
fog 0.7.1
ruby 1.9.2 under rvm

I'm using Carrierwave 0.5.3 and Fog to upload images to Amazon-S3.

The setup works smoothly when running locally, no errors.

But when running on Heroku, uploads fail with this message:

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'

I've got an initializer:

# /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

And an uploader:

# /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

I've traced the error message to Fog, and it seems that Fog, under Heroku, isn't getting the config info from the initializer. :provider is somehow empty. But I'm stumped as to how to fix it.

Any help would be much appreciated.

I'm using:

rails 3.0.4
heroku 1.19.1
fog 0.7.1
ruby 1.9.2 under rvm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路弥 2024-11-04 00:34:23

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

The error was due to the fact that I had mistakenly added the initializer to the .gitignore-file. Thus, it was never uploaded to Heroku.

遗心遗梦遗幸福 2024-11-04 00:34:23

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

在我的头撞到墙上几个小时后,我发现我在载波初始化器的开头有这一行:

if Rails.env.test?
  ...

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

Adding this for completeness...

After smashing my head against the wall for hours with this error message, I found out that I had this line at the beginning of the carrierwave initializer:

if Rails.env.test?
  ...

So the initializer was only considered in the test environment. After removing it, everything worked as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文