[英]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. 在上面找到解决方案的地方添加链接。
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.