1
votes

I have been trying to setup CarrierWave with Sinatra and Fog for S3 File Management. I constantly keep running into issues around Fog being undefined. This works fine the moment I change the storage to :file.

I have so far also tried solutions mentiohed here NameError: uninitialized constant CarrierWave::Storage::Fog and here NameError: uninitialized constant CarrierWave::Storage::Fog, heroku

But I have had no luck so far.

Here's my overall setup

Gemfile

gem 'fog', require: 'fog/aws'
gem 'carrierwave', '~> 2.0'

app.rb

require "carrierwave"

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:              'fog/aws',                        # required
    aws_access_key_id:     ENV['AWS_ACCESS_KEY_ID'],     # required unless using use_iam_profile
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], # required unless using use_iam_profile
    use_iam_profile:       true,                         # optional, defaults to false
    region:                ENV['AWS_REGION'],            # optional, defaults to 'us-east-1'
  }
  config.fog_directory  = ENV['S3_BUCKET_NAME']
  config.fog_public     = false                                                 # optional, defaults to true
  config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
    config.fog_provider = 'fog/aws'
end

Added this to my user class

mount_uploader :profile_picture, ProfileImageUploader

And lastly my ProfileImageUploader

class ProfileImageUploader < CarrierWave::Uploader::Base
  storage :fog
end

I am still stuck at this output

NameError: uninitialized constant Fog
from ~/.rvm/gems/ruby-2.7.0/gems/carrierwave-2.1.0/lib/carrierwave/storage/fog.rb:159:in `connection'
1
You need also require fog: require "fog"hypee
Stilling hitting a wall though LoadError: cannot load such file -- excon from /Users/anuragramdasan/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in require'`Anurag Ramdasan
It's based on Rails so there's a good chance you will need to include require 'active_support' to access different resource used by fog and carrierwavehypee
I doubt that coz the error seems to be coming from activesupport module. So I am not really sure finding activesupport is the issue. Rather seems like excon within activesupport is not being found.Anurag Ramdasan

1 Answers

0
votes

try using
gem 'fog-aws'
and then
require 'sinatra/activerecord'
require 'carrierwave'
require 'carrierwave/orm/activerecord'
require 'fog/aws'