'missing required option :name

I am trying to set up AWS, and carrierwave to upload pictures from my website. I keep getting the error 'missing required option :name' when I try to upload/update the posts though. I have followed tutorials to set up my S3 account and to get carrierwave.rb set up. Please let me know if you have any ideas!

carrierwave.rb

CarrierWave.configure do |config|
 config.storage    = :aws
 config.aws_bucket = ENV['S3_BUCKET_NAME']
 config.aws_acl    = 'public-read'
 config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
 config.aws_attributes = {
   expires: 1.week.from_now.httpdate,
   cache_control: 'max-age=604800'
 }

 config.aws_credentials = {
   access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
   secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
   region:            ENV['AWS_REGION']
 }
end

.env example

S3_BUCKET_NAME=*****
AWS_ACCESS_KEY_ID=*****
AWS_SECRET_ACCESS_KEY=*****
AWS_REGION=*****

portfolio_uploader.rb

class PortfolioUploader < CarrierWave::Uploader::Base

  storage :aws

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end


Solution 1:[1]

I ran into this issue too. The error message is deceptive. I found that it is actually the config.aws_bucket = ENV['S3_BUCKET_NAME'] line that was causing the issue. If config.aws_bucket is nil (such as when the ENV['S3_BUCKET_NAME'] is unset, you will get the deceptive missing required option :name in the console.

Solution 2:[2]

I had an identical issue, try to restart the rails server, when you are making any changes to your config folder you have to restart the server.

Solution 3:[3]

For some reason, I saw Carrierwave.rb file was deleted from my App's config >> Initializers folder. recreating the same fixed the issue. Hope it helps someone.

Solution 4:[4]

This can also happen if you've got your bucket name / keys in an encrypted credentials file but don't have your .key file(s) setup correctly / Rails can't read the credentials file, FYI!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PressingOnAlways
Solution 2 Bol_Plecow
Solution 3 Rajkumar Das
Solution 4 Jon Sullivan