我一直在尝试使用 Sinatra 和 Fog 为 S3 文件管理设置 CarrierWave。我经常遇到关于雾未定义的问题。当我将存储更改为 :file 时,这可以正常工作。
到目前为止,我还尝试过这里提到的解决方案NameError: uninitialized constant CarrierWave::Storage::Fog和NameError: uninitialized constant CarrierWave::Storage::Fog, heroku
但到目前为止我还没有运气。
这是我的整体设置
宝石文件
gem 'fog', require: 'fog/aws'
gem 'carrierwave', '~> 2.0'
应用程序.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
将此添加到我的用户类
mount_uploader :profile_picture, ProfileImageUploader
最后是我的 ProfileImageUploader
class ProfileImageUploader < CarrierWave::Uploader::Base
storage :fog
end
我仍然停留在这个输出
NameError: uninitialized constant Fog
from ~/.rvm/gems/ruby-2.7.0/gems/carrierwave-2.1.0/lib/carrierwave/storage/fog.rb:159:in `connection'