Carrierwave/Fog-azure: azure is not a recognized provider (ArgumentError) - ruby-on-rails

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.

Related

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. 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

Rails error with CarrierWave and S3 on Heroku, TypeError: no implicit conversion of nil into String

I am unable to upload images using CarrierWave and S3. I am using these gems:
gem 'carrierwave'
gem 'carrierwave-aws'
I have the configuration set up properly, in the code, environment variables, and on AWS:
CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = ENV["S3_BUCKET_NAME"]
config.aws_acl = 'public-read'
config.aws_credentials = {
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
region: ENV["AWS_REGION"]
}
config.cache_dir = "#{Rails.root}/tmp/uploads"
end
class ImageUploader < CarrierWave::Uploader::Base
storage :aws
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
One source said to include the cache_dir lines specifically for Heroku inside the uploader, but it seems to have no effect:
https://github.com/carrierwaveuploader/carrierwave/wiki/how-to%3A-make-carrierwave-work-on-heroku
Here is some standard code to save an image, but it gives an error:
> url = "https://dl.dropboxusercontent.com/u/22125572/Kira_opt.jpg"
> image = open(url)
> user = User.first
> user.image = image
TypeError: no implicit conversion of nil into String
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:171:in `join'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:171:in `cache_path'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:143:in `block in cache!'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:134:in `cache!'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/mount.rb:329:in `cache'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/mount.rb:163:in `image='
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/orm/activerecord.rb:39:in `image='
from (irb):4
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
It looks like the way I should have saved the remote image is using:
url = "https://dl.dropboxusercontent.com/u/22125572/Kira_opt.jpg"
user = User.first
user.remote_image_url = url
user.save
which means the url doesn't need to be opened at all.

Carrierwave / Fog / S3 "is not a recognized storage provider"

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.

Carrierwave fails in production: Can't convert nil into string

I'm using Fog and uploading to S3. Uploading works fine in development, but when in production, it gives me this error:
TypeError (can't convert nil into String):
app/controllers/pictures_controller.rb:29:in `create'
(that line is where the picture gets saved). That's the end of the stack trace.
When I go into the console and do:
p = Picture.new(image: "~/rails_apps/my_app/current/app/assets/images/rails.png")
It gives me the following in production:
CarrierWave::FormNotMultipart: CarrierWave::FormNotMultipart
...but makes no protest in development. Perhaps that is a clue.
Any ideas why uploads aren't working in production?
Here's my carrierwave.rb initializer:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'], # required
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']#, # required
}
if Rails.env.production?
config.fog_directory = 'mydir' # required
else
config.fog_directory = 'mydir-development' # required
end
config.fog_public = true # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
I encountered similar problem, it turned out that my carrierwave and fog gem are outdated(they worked perfectly until I upgraded to Rails 4). Maybe you can give it a try.
gem 'carrierwave', '0.9.0'
gem 'fog', '~> 1.3.1'

Rspec and Carrierwave. When changing config.storage to file for testing, I get an ArgumentError is not a recognized storage provider exception

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.

Resources