简体   繁体   English

未初始化的常量CarrierWave :: Storage :: Fog与Google Cloud Storage

[英]uninitialized constant CarrierWave::Storage::Fog with Google Cloud Storage

I have seen lots of other people having similar problems to me but none of the listed solutions apply so I am hoping this awesome community can help me out. 我看到许多其他人也遇到类似的问题,但是没有列出的解决方案适用,所以我希望这个很棒的社区能够为我提供帮助。

I am trying to use the sitemap_generator gem but I host with Heroku so I am trying to follow their documentation here to use Carrierwave to upload the sitemaps to Google Cloud Storage. 我正在尝试使用sitemap_generator gem,但我在Heroku中托管,因此我试图按照此处的文档使用Carrierwave将站点地图上传到Google Cloud Storage。 I am already using Google Cloud to upload my images with all works fine so I was hoping it would be straightforward however the files are not being uploaded. 我已经在使用Google Cloud上传我的图片,并且一切正常,所以我希望它很简单,但是文件并未上传。 The documentation says you need to add: 该文档说您需要添加:

config.storage = :fog

To your carrierwave config file however whenever I add it, I get the following error: 但是,无论何时添加到您的载波配置文件中,都会收到以下错误:

gems/carrierwave-49fdad1ec6ca/lib/carrierwave/uploader/configuration.rb:75:in `eval': uninitialized constant CarrierWave::Storage::Fog (NameError)

My Carrierwave config looks like this: 我的Carrierwave配置如下所示:

CarrierWave.configure do |config|
     config.cache_dir = "#{Rails.root}/tmp/"
     config.storage = :fog
     config.fog_credentials = {
         :provider => 'Google'
     }
     config.fog_directory = 'bucket-name'
     config.asset_host = 'https://domain.storage.googleapis.com'
end

(fog_directory and asset_host are replaced with dummy values) (fog_directory和asset_host替换为虚拟值)

And in my gem file I have: 在我的gem文件中,我有:

gem 'fog'
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'

I have seen a lot of people using AWS with the same error but their solution is to change to use fog gem instead of fog-aws (which I am already doing) and require fog/aws. 我已经看到很多人在使用AWS时遇到相同的错误,但是他们的解决方案是更改为使用雾宝石而不是雾化aws(我已经在这样做)并且需要雾化/ aws。 I have tested this like so: 我已经这样测试过了:

gem 'fog', require: 'fog/google'

But still have the same issue. 但是仍然有同样的问题。

Can anyone suggest what I can do to try and resolve this? 谁能建议我可以做些什么来解决这个问题? Any help would be greatly appreciated!! 任何帮助将不胜感激!!

Many thanks 非常感谢

I got the same error using fog-aws for Amazon S3. 使用Amazon S3的雾化aws时遇到了相同的错误。 It seems this error occurs if storage is fog, doesn't matter it's amazon s3 or google cloud. 如果存储空间模糊,似乎发生此错误,无论是Amazon S3还是Google Cloud。

I used carrierwave gem to upload user profile picture so I solved this by moving storage configuration after credentials configuration as below: 我使用了carrierwave gem来上传用户个人资料图片,因此我通过在凭据配置之后移动存储配置来解决此问题,如下所示:

CarrierWave.configure do |config|
  if Rails.env.staging? || Rails.env.production?
    config.fog_provider = 'fog/aws'
    config.fog_credentials = {
      provider: 'AWS',
      aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
      aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
      region: ENV['AWS_REGION']
    }
    config.storage = :fog
    config.fog_directory = ENV['S3_BUCKET']
    config.fog_public    = true
    config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" }
  else
    config.storage = :file
    config.enable_processing = Rails.env.development?
  end
end

Another solution was to add require 'carrierwave/storage/fog' at the top, in above file. 另一个解决方案是在上述文件的顶部添加require 'carrierwave/storage/fog' For me the file was carrier_wave.rb under initializers directory. 对我来说,该文件是在initializers目录下的carrier_wave.rb。

Adding links where I found above solutions. 在上面找到解决方案的地方添加链接。

Medium Carrierwave Fog 中等 Carrierwave

I know this post is 7 months old but i just wasted 36h trying to implement that same gem... no luck. 我知道这个帖子已经有7个月了,但是我只是浪费了36h来尝试实现同样的宝石……没有运气。 It seems that documentation is slightly outdated. 看来文档有些过时了。

If you ask me, fog-google is unnecessary at this point! 如果您问我,这时就没有必要使用fog-google

Try this gem for CarrierWaveUploader integration with google. 尝试将此宝石用于与Google集成的CarrierWaveUploader。

carrierwave-google-storage github carrierwave-google-storage github

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

相关问题 NameError:未初始化的常量CarrierWave :: Storage :: Fog,heroku - NameError: uninitialized constant CarrierWave::Storage::Fog, heroku NameError: 未初始化的常量 CarrierWave::Storage::Fog - NameError: uninitialized constant CarrierWave::Storage::Fog NameError:未初始化的常量CarrierWave :: Storage :: Heroku日志中的雾 - NameError: uninitialized constant CarrierWave::Storage::Fog in Heroku Logs Paperclip,未初始化的常量Paperclip :: Storage :: Fog :: Excon - Paperclip, uninitialized constant Paperclip::Storage::Fog::Excon 尝试使用Fog和Carrierwave将文件保存到Google云端存储时出现“Excon :: Error :: Forbidden”错误 - “Excon::Error::Forbidden” error when trying to save files to Google Cloud Storage with Fog and Carrierwave 使用 Google Cloud Storage 和 Carrierwave 保存图像时出错 - Errors in saving image with Google Cloud Storage and Carrierwave 载波雾本地存储完整附件路径 - Carrierwave fog local storage full attachment path Carrierwave / Fog / S3“不是公认的存储提供商” - Carrierwave / Fog / S3 “is not a recognized storage provider” 使用Fog时Google Cloud Storage中的多余对象 - Extra object in Google Cloud Storage when using Fog CarrierWave无法使用Fog和S3:ArgumentError ...“不是公认的存储提供程序” - CarrierWave not working with Fog and S3: ArgumentError…“is not a recognized storage provider”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM