Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 493
Steph Simpson Avatar asked Jun 18 '18 15:06

Steph Simpson


2 Answers

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.

like image 170
PressingOnAlways Avatar answered Nov 05 '22 13:11

PressingOnAlways


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.

like image 30
Bol_Plecow Avatar answered Nov 05 '22 14:11

Bol_Plecow