简体   繁体   English

CarrierWave无法使用Fog和S3:ArgumentError ...“不是公认的存储提供程序”

[英]CarrierWave not working with Fog and S3: ArgumentError…“is not a recognized storage provider”

Maybe this is a bug in CarrierWave? 也许这是CarrierWave中的一个错误? I read similar questions here, tried example code and to reproduce a new app, and it is not working. 我在这里阅读类似的问题,尝试了示例代码并重现了一个新的应用程序,但它无法正常工作。

I tried old apps with their code that is like the examples on Github, but now it doesn't work. 我尝试使用类似Github上的示例的旧应用程序,但现在它不起作用。

Full trace: here Gemfile 完整跟踪: 这里是 Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.2'

gem 'mini_magick', '~> 3.4'
gem 'carrierwave', '~> 0.5.8'
gem 'fog'
gem 'activeadmin', '~> 0.4.3'
gem 'httparty'
gem 'dalli'
gem 'json'
gem "mercury-rails", :git => "https://github.com/jejacks0n/mercury.git"
gem 'newrelic_rpm'

group :assets do
  gem 'sass-rails',   '~> 3.2.4'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'jquery_datepicker'
group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

This is the carrierwave configuration: 这是carrierwave配置:

# config/carrierwave.rb
# encoding: utf-8
require 'carrierwave'

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',       # required
    :aws_access_key_id      => 'ACCESS_KEY', # required
    :aws_secret_access_key  => 'SECRET_KEY', # required
    :region                 => 'eu-west-1'  # optional, defaults to 'us-east-1'
  }
  config.fog_directory  = 'lkrails'                     # required
  config.fog_host       = 'https://lkrails.s3-eu-west-1.amazonaws.com'
  config.fog_public     = true # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}

   # Make the tmp dir work on Heroku
   #  config.cache_dir = "#{Rails.root}/tmp/uploads"
end

This is The uploader 这是上传者

# uploaders/images_uploader.rb
class ImagesUploader < CarrierWave::Uploader::Base
    include CarrierWave::MiniMagick
    storage :fog

    def store_dir
        "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
    version :tiny do
       process :resize_to_limit => [25, 25]
    end
    version :thumb do
       process :resize_to_limit => [50, 50]
    end
    version :medium do
        process :resize_to_limit => [120, 120]
    end

    def extension_white_list
       %w(jpg jpeg gif png)
    end

    def filename 
    if original_filename 
      @name ||= Digest::MD5.hexdigest(File.dirname(current_path))
      "#{@name}.#{file.extension}"
    end
end

According to your logfile, your version of fog is very very old. 根据您的日志文件,您的雾版本非常老。 You're using 0.3.25, and the most recent tag is at 1.1.2. 您使用的是0.3.25,最新的标签是1.1.2。 Try doing this: 试着这样做:

bundle update fog

Your version of carrierwave is similarly out of date, so I'd bundle update carrierwave as well. 您的版本的carrierwave也同样过时了,所以我也bundle update carrierwave That should help correct this issue. 这应该有助于纠正这个问题。

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: 用这个错误信息将我的头撞到墙上几个小时之后,我发现我在carrierwave初始化器的开头有这条线:

if Rails.env.test?
  ...

So the initializer was only considered in the test environment. 因此初始化程序仅在测试环境中考虑。 After removing it, everything worked as expected. 删除后,一切都按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM