11

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
Steph Simpson
  • 111
  • 1
  • 4
  • What is the *exact* error? When/where do you see this error? – Dave Newton Jun 18 '18 at 15:27
  • Completed 500 Internal Server Error in 102ms (ActiveRecord: 23.0ms) ArgumentError (missing required option :name) Is the error. It happens when i try to update or create a portfolio item with an image. – Steph Simpson Jun 18 '18 at 15:45
  • Try to use `ENV.fetch` instead of `ENV[]` – Mattia M. Jun 18 '18 at 15:52
  • Just tried .fetch and still get the same error – Steph Simpson Jun 18 '18 at 15:57
  • can u post error log also ? – 7urkm3n Jun 18 '18 at 16:05
  • There isn't much more than that in the logs: ↳ app/controllers/portfolios_controller.rb:43 [1m[35m (0.2ms)[0m [1m[31mROLLBACK[0m ↳ app/controllers/portfolios_controller.rb:43 Completed 500 Internal Server Error in 75ms (ActiveRecord: 19.2ms) ArgumentError (missing required option :name): app/controllers/portfolios_controller.rb:43:in `block in update' app/controllers/portfolios_controller.rb:42:in `update' – Steph Simpson Jun 18 '18 at 16:15
  • Seeing the same error since switching from `fog` to `carrierwave-aws`. :name does not seem to be related to the actual activerecord model validation. – YWCA Hello Oct 29 '18 at 16:40
  • @StephSimpson - I'm going through the same issue. – shivamkaushik Sep 24 '19 at 10:25

4 Answers4

13

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.

PressingOnAlways
  • 11,948
  • 6
  • 32
  • 59
1

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.

Bol_Plecow
  • 13
  • 2
0

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.

0

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!

Jon Sullivan
  • 193
  • 2
  • 6