加载到Heroku时Carrierwave/fog/AWS问题“无法加载这样的文件 - 雾”

因此,我是一个新手,并通过Michael Hartl的rails教程。在尝试使用CarrierWave配置图片上传时,我完全陷入困境,对S3 AWS进行雾视图上传。当推到Heroku的,我得到以下错误:加载到Heroku时Carrierwave/fog/AWS问题“无法加载这样的文件 - 雾”

LoadError:无法加载这样的文件 - 雾

作为一个方面说明我已经使用在开发模式完全相同的代码试过,导轨服务器只是工作很好,我可以成功将文件上传到AWS。所以这不是AWS的配置设置问题。尝试将应用推送到Heroku时出现问题。

这里是我的设置: 的Gemfile

source 'https://rubygems.org' 

gem 'rails', '5.1.4'

gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'

gem 'faker', '1.7.3'

gem 'carrierwave', '1.0.0'

gem 'fog-aws', '2.0.0'

gem 'mini_magick', '4.7.0'

gem 'nokogiri', '1.8.1'

gem 'will_paginate', '3.1.6'

gem 'bootstrap-will_paginate', '1.0.0'

gem 'bootstrap-sass', '3.3.7'

gem 'puma', '3.9.1'

gem 'sass-rails', '5.0.6'

gem 'uglifier', '3.2.0'

gem 'coffee-rails', '4.2.2'

gem 'jquery-rails', '4.3.1'

gem 'turbolinks', '5.0.1'

gem 'jbuilder', '2.7.0'

group :development, :test do

gem 'sqlite3', '1.3.13'

gem 'byebug', '9.0.6', platform: :mri

end

group :development do

gem 'web-console', '3.5.1'

gem 'listen', '3.0.8'

gem 'spring', '2.0.2'

gem 'spring-watcher-listen', '2.0.1'

end

group :test do

gem 'rails-controller-testing', '1.0.2'

gem 'minitest-reporters', '1.1.14'

gem 'guard', '2.13.0'

gem 'guard-minitest', '2.4.4'

end

group :production do

gem 'pg', '0.18.4'

end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

应用程序/上传/ picture_uploader.rb

class PictureUploader < CarrierWave::Uploader::Base 

include CarrierWave::MiniMagick

process resize_to_limit: [400, 400]

if Rails.env.production?

storage :fog

else

storage :file

end

配置/初始化/ carrierwave.rb

if Rails.env.production? 

CarrierWave.configure do |config|

config.fog_provider = 'fog/aws'

config.fog_credentials = {

# Configuration for Amazon S3

:provider => 'AWS',

:aws_access_key_id => ENV['S3_ACCESS_KEY'],

:aws_secret_access_key => ENV['S3_SECRET_KEY'],

:region => ENV['S3_REGION'],

}

config.cache_dir = "#{Rails.root}/tmp/uploads" # For Heroku

config.fog_directory = ENV['S3_BUCKET']

config.fog_public = true

config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" }

end

end

Heroku的日志,错误:

!  Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used. 

Detected buildpacks: Ruby,Node.js

See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order

-----> Ruby app detected

-----> Compiling Ruby/Rails

-----> Using Ruby version: ruby-2.3.4

###### WARNING:

Removing `Gemfile.lock` because it was generated on Windows.

Bundler will do a full resolve so native gems are handled properly.

This may result in unexpected gem versions being used in your app.

In rare occasions Bundler may not be able to resolve your dependencies at all.

https://devcenter.heroku.com/articles/bundler-windows-gemfile

-----> Installing dependencies using bundler 1.15.2

Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4

Fetching https://github.com/codahale/bcrypt-ruby.git

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.

Fetching gem metadata from https://rubygems.org/.........

Fetching version metadata from https://rubygems.org/..

Fetching dependency metadata from https://rubygems.org/.

Resolving dependencies...

Fetching rake 12.3.0

Fetching concurrent-ruby 1.0.5

Fetching minitest 5.10.3

Installing minitest 5.10.3

Installing rake 12.3.0

Installing concurrent-ruby 1.0.5

Fetching thread_safe 0.3.6

Installing thread_safe 0.3.6

Fetching builder 3.2.3

Installing builder 3.2.3

Fetching erubi 1.7.0

Fetching mini_portile2 2.3.0

Installing erubi 1.7.0

Fetching crass 1.0.3

Installing mini_portile2 2.3.0

Fetching rack 2.0.3

Installing crass 1.0.3

Fetching nio4r 2.2.0

Installing rack 2.0.3

Installing nio4r 2.2.0 with native extensions

Fetching websocket-extensions 0.1.3

Installing websocket-extensions 0.1.3

Fetching mini_mime 1.0.0

Installing mini_mime 1.0.0

Fetching arel 8.0.0

Installing arel 8.0.0

Fetching execjs 2.7.0

Using bcrypt 3.1.11 from https://github.com/codahale/bcrypt-ruby.git (at [email protected])

Installing execjs 2.7.0

Fetching rb-fsevent 0.10.2

Installing rb-fsevent 0.10.2

Fetching ffi 1.9.18

Installing ffi 1.9.18 with native extensions

Fetching will_paginate 3.1.6

Installing will_paginate 3.1.6

Using bundler 1.15.2

Fetching mime-types-data 3.2016.0521

Installing mime-types-data 3.2016.0521

Fetching coffee-script-source 1.12.2

Installing coffee-script-source 1.12.2

Fetching method_source 0.9.0

Installing method_source 0.9.0

Fetching thor 0.20.0

Installing thor 0.20.0

Fetching excon 0.60.0

Installing excon 0.60.0

Fetching formatador 0.2.5

Installing formatador 0.2.5

Fetching multi_json 1.12.2

Installing multi_json 1.12.2

Fetching ipaddress 0.8.3

Installing ipaddress 0.8.3

Fetching mini_magick 4.7.0

Installing mini_magick 4.7.0

Fetching pg 0.18.4

Installing pg 0.18.4 with native extensions

Fetching puma 3.9.1

Installing puma 3.9.1 with native extensions

Fetching tilt 2.0.8

Installing tilt 2.0.8

Fetching turbolinks-source 5.0.3

Installing turbolinks-source 5.0.3

Fetching i18n 0.9.1

Installing i18n 0.9.1

Fetching tzinfo 1.2.4

Installing tzinfo 1.2.4

Fetching nokogiri 1.8.1

Installing nokogiri 1.8.1 with native extensions

Fetching websocket-driver 0.6.5

Installing websocket-driver 0.6.5 with native extensions

Fetching mail 2.7.0

Installing mail 2.7.0

Fetching rack-test 0.8.2

Installing rack-test 0.8.2

Fetching sprockets 3.7.1

Installing sprockets 3.7.1

Fetching autoprefixer-rails 7.2.3

Installing autoprefixer-rails 7.2.3

Fetching uglifier 3.2.0

Installing uglifier 3.2.0

Fetching bootstrap-will_paginate 1.0.0

Installing bootstrap-will_paginate 1.0.0

Fetching mime-types 3.1

Installing mime-types 3.1

Fetching coffee-script 2.4.1

Installing coffee-script 2.4.1

Fetching fog-core 1.45.0

Installing fog-core 1.45.0

Fetching rb-inotify 0.9.10

Installing rb-inotify 0.9.10

Fetching turbolinks 5.0.1

Installing turbolinks 5.0.1

Fetching faker 1.7.3

Installing faker 1.7.3

Fetching activesupport 5.1.4

Installing activesupport 5.1.4

Fetching fog-json 1.0.2

Installing fog-json 1.0.2

Fetching sass-listen 4.0.0

Installing sass-listen 4.0.0

Fetching globalid 0.4.1

Installing globalid 0.4.1

Fetching activemodel 5.1.4

Installing activemodel 5.1.4

Fetching jbuilder 2.7.0

Installing jbuilder 2.7.0

Fetching sass 3.5.4

Installing sass 3.5.4

Fetching activejob 5.1.4

Installing activejob 5.1.4

Fetching activerecord 5.1.4

Installing activerecord 5.1.4

Fetching carrierwave 1.1.0

Installing carrierwave 1.1.0

Fetching bootstrap-sass 3.3.7

Installing bootstrap-sass 3.3.7

Fetching rails-dom-testing 2.0.3

Fetching loofah 2.1.1

Installing rails-dom-testing 2.0.3

Installing loofah 2.1.1

Fetching fog-xml 0.1.3

Installing fog-xml 0.1.3

Fetching rails-html-sanitizer 1.0.3

Installing rails-html-sanitizer 1.0.3

Fetching fog-aws 2.0.0

Fetching actionview 5.1.4

Installing actionview 5.1.4

Installing fog-aws 2.0.0

Fetching actionpack 5.1.4

Installing actionpack 5.1.4

Fetching actioncable 5.1.4

Fetching actionmailer 5.1.4

Installing actionmailer 5.1.4

Installing actioncable 5.1.4

Fetching railties 5.1.4

Fetching sprockets-rails 3.2.1

Installing sprockets-rails 3.2.1

Installing railties 5.1.4

Fetching coffee-rails 4.2.2

Fetching jquery-rails 4.3.1

Installing coffee-rails 4.2.2

Fetching rails 5.1.4

Installing rails 5.1.4

Fetching sass-rails 5.0.6

Installing sass-rails 5.0.6

Installing jquery-rails 4.3.1

Bundle complete! 29 Gemfile dependencies, 74 gems now installed.

Gems in the groups development and test were not installed.

Bundled gems are installed into ./vendor/bundle.

Bundle completed (32.67s)

Cleaning up the bundler cache.

-----> Installing node-v6.11.1-linux-x64

-----> Detecting rake tasks

-----> Preparing app for Rails asset pipeline

Running: rake assets:precompile

rake aborted!

LoadError: cannot load such file -- fog

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:122:in `eager_load_fog'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:137:in `fog_credentials='

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/config/initializers/carrier_wave.rb:3:in `block in <top (required)>'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:159:in `configure'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.1.0/lib/carrierwave.rb:14:in `configure'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/config/initializers/carrier_wave.rb:2:in `<top (required)>'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:655:in `block in load_config_initializer'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/notifications.rb:168:in `instrument'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:654:in `load_config_initializer'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:611:in `each'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/engine.rb:611:in `block in <class:Engine>'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:48:in `each'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:48:in `tsort_each_child'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/config/environment.rb:5:in `<top (required)>'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:329:in `require'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:329:in `require_environment!'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:445:in `block in run_tasks_blocks'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'

/tmp/build_09f91bebad38e0d893f4a5cd532d3b6b/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'

Tasks: TOP => environment

(See full trace by running task with --trace)

!

! Precompiling assets failed.

!

! Push rejected, failed to compile Ruby app.

! Push failed

回答:

首先,卸载宝石然后安装这是1.2.1

回答:

尝试直接添加宝石 '雾' 到您的Gemfile

的Gemfile最新版本:

gem 'fog' 

gem 'fog-aws'

如果您在Gemfile中定义gem,它会自动需要它(默认情况下)。

回答:

微小更新:我能够在开发模式下重现Heroku部署生产错误。

LoadError: cannot load such file -- fog

的Gemfile:

gem 'carrierwave',    '1.1.0' #also tried 1.2.1 with same results 

gem 'mini_magick', '4.7.0'

gem 'fog-aws', '2.0.0'

配置/ initiliazers/carrierwave.rb

if Rails.env.production? 

CarrierWave.configure do |config|

config.fog_credentials = {

# Configuration for Amazon S3

:provider => 'AWS',

:aws_access_key_id => ENV['S3_ACCESS_KEY'],

:aws_secret_access_key => ENV['S3_SECRET_KEY']

}

config.fog_directory = ENV['S3_BUCKET']

end

在发展中解决模式问题以下任一步骤的工作对我来说:

1)在证书之前将以下内容添加到carrierwave.rb(并且仅限于 宝石'雾AWS' 在Gemfile中):

config.fog_provider = 'fog/aws' 

2)添加雾宝石到的Gemfile:

gem 'fog', '1.41' 

有了这个carrierwave图片上传到Amazon S3现在是在发展模式下完全正常。不幸的是,这并不能解决部署到Heroku的问题。 Heroku无法根据以上情况建立提供商吗?生产日志表明雾安装,所以我没有得到它。

回答:

最后解决了这个问题,它非常简单。真令人尴尬! 所有我需要做的是在Heroku的重置数据库(前推)

heroku pg:reset DATABASE 

现在部署Heroku的工作没有崩溃(包括图片上传到S3 AWS)

以上是 加载到Heroku时Carrierwave/fog/AWS问题“无法加载这样的文件 - 雾” 的全部内容, 来源链接: utcz.com/qa/265648.html

回到顶部