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. 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. 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.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)
And in my gem file I have:
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. 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. It seems this error occurs if storage is fog, doesn't matter it's amazon s3 or 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.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. For me the file was carrier_wave.rb under initializers directory.
Adding links where I found above solutions.
Medium Carrierwave Fog
I know this post is 7 months old but i just wasted 36h trying to implement that same gem... no luck. It seems that documentation is slightly outdated.
If you ask me, fog-google is unnecessary at this point!
Try this gem for CarrierWaveUploader integration with google.
carrierwave-google-storage github
Related
I'm trying to connect my rails 4 project to Azure, I use carrierwave and fog for managing and storing the images.
This is the error I get when starting the server or the console:
/Users/giulio/.rvm/gems/ruby-2.2.1#my_project/gems/fog-core-1.32.0/lib/fog/core/services_mixin.rb:12:in `new': azure is not a recognized provider (ArgumentError)
from /Users/giulio/.rvm/gems/ruby-2.2.1#my_project/gems/fog-core-1.32.0/lib/fog/storage.rb:22:in `new'
from /Users/giulio/.rvm/gems/ruby-2.2.1#my_project/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
from /Users/giulio/.rvm/gems/ruby-2.2.1#my_project/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
from /Users/giulio/Documents/rails/my_project/config/initializers/carrier_wave.rb:7:in `block in <top (required)>'
I have in my gemfile:
gem 'carrierwave'
gem 'fog'
gem 'fog-azure'
Carrierwave initializer is:
CarrierWave.configure do |config|
if Rails.env.test?
config.storage = :file
config.enable_processing = false
else
config.storage = :fog
config.fog_credentials = Rails.application.secrets.fog_credentials.symbolize_keys
config.fog_directory = "my_directory"
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'public, max-age=315576000'}
end
end
my secrets.yml contains:
fog_credentials:
provider: 'azure'
azure_sub_id: '12a2341c-22ac-1561-5ed2-17865d910ba4'
azure_pem: '~/secret.pem'
azure_api_url: 'usnorth.management.core.windows.net'
Checking into fog-azure gem code I figured that fog-azure deals only with the 'Compute' module of fog, while carrierwave uses the 'storage' module.
From this I understand that the fog-azure can only be used for managing servers (i.e. starting, stopping, provisioning) not with the storage
I found also carrierwave-azure gem to get carrierwave to support azure, I'll be trying this.
I just pulled an older version of a project I'm working on in rails from github and am having problems with carrierwave for image upload. I used the figaro gem to store my secret keys so they were not in the file I pulled down (figaro puts an application.yml file that then gets listed in .gitignor). So I added the figaro configuration, but carrierwave still refuses to work. I even tried putting the keys into the carrierwave configuration directly to see if it was something with figaro, but no luck.
My config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['AWS_KEY_ID'],
:aws_secret_access_key => ENV['AWS_SECRET_KEY'],
:region => 'us-east-1',
}
config.fog_directory = 'bucketname'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
I am pretty sure that my keys are being stored properly in my development environment, but I have no idea why carrierwave is not working like it did before.
Thanks!
I have a Rails app that is using Carrierwave for file uploads. It has been working fine but I want to start using Amazon S3 for my image storage. I am getting this error:
ArgumentError ( is not a recognized storage provider):
app/controllers/salons_controller.rb:52:in `update'
I have made sure I have the latest gems for Carrierwave and Fog. This is in my Gemfile:
gem 'carrierwave'
gem 'aws-sdk'
gem 'fog'
fog.rb looks like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'MYACCESSKEY',
:aws_secret_access_key => 'MYSECRETKACCESSKEY',
:region => 'us-east-1'
}
config.fog_directory = 'andrunix'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
The Uploader class looks like:
class SalonImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
# "andrunix" is the bucket name on S3
"andrunix/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
If I change the storage back to 'file', it works fine. Setting storage to 'fog' generates this error.
OK, I'm an idiot. :)
At some point, I don't know where, I added a fog.rb file with my CarrierWave configuration to the lib/carrierwave/storage directory. I got desperate, paid for a Railscasts subscription so I could watch episode #383 (http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true) and at 3:02 I found the error of my ways. The Carrierwave configuration needed to be placed in config/initializers/carrierwave.rb.
I don't know where I got this other location but once I moved the config to the proper location, everything is good.
I just ran into the same problem, and people must be aware that any typo in the config file : "config/initializers/carrierwave.rb", leads to that error.
I have two carrierwave uploaders in my application. ImageUploader is for uploading locally and ImageRemoteUploader for uploading to Amazon S3 storage using fog. ImageUploader has storage set to :file and ImageRemoteUploader has storage set to :fog. This setup works fine, but when I start to set up my rspec tests, things change.
The problem arises when I change the ImageRemoteUploader to use :file storage during testing. I do this in my fog initialization file. The file,
/config/initializers/fog.rb, looks like:
CarrierWave.configure do |config|
if Rails.env.test?
config.storage = :file
config.enable_processing = false
else
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'XXXXXXXX', # required
:aws_secret_access_key => 'XXXXXX', # required
:region => 'XXXX' # optional, defaults to 'us-east-1'
}
config.fog_directory = 'xxx' # required
config.fog_public = true
end
end
When I do this, I get an ArgumentError is not a recognized storage provider carrierwave exception. When I use the fog credentials (I don't set config.storage to :file), the test works as expected.
Carrierwave 0.7.1, Rails 3.2.8, Ruby 1.9.3, Rspec 2.10
Thanks.
I'd try moving the config.storage and config.enable_processing lines into lib/initializers/carrierwave.rb, as recommended in the Carrierwave docs.
Fog also has its own mocking support, which is enabled by running Fog.mock! before the examples. This might be a better approach.
I am using carrierwave with fog to store images on amazon's s3. I've followed all the guides, but i keep getting the same basic error and it seems incorrectly.
Errno::EACCES in ProjectsController#update
Permission denied - C:/rails-projects/myrailsapp/tmp/20111203-2006-7864-6681/jolly-rows.jpg
however, the uploaded image is still being placed in the cached dir and it's being uploaded to the amazon s3 server.... so why is it throwing this error?
i have
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'SECRET',
:aws_secret_access_key => 'SECRET'
}
config.permissions = 0777
config.fog_directory = 'ia_test_dir'
config.fog_public = true
end
in an initializer. please help...thanks!
Update: still haven't been able to get this to work. I've a few other things, like changing the tmp dir, not setting the tmp, etc.. and nothing please help. anyone?
Is there something my question is missing that's keeping people from responding?