carrierwaveuploader / carrierwave-aws

AWS-SDK storage adapter for CarrierWave
MIT License
409 stars 107 forks source link

NoMethodError (undefined method `match' for nil:NilClass Did you mean? catch): #130

Closed mkeefe closed 6 years ago

mkeefe commented 6 years ago

Very weird bug, albeit with no context or trace. Google says its a region error on AWS, but i've tried a few different regions (S3 is global) as well as a different bucket.

Here is my GemFile excerpt

gem "carrierwave", "~> 1.0" # For Uploads
gem "carrierwave-aws"

Here is my carrierwave.rb config file

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = "nub-test-bucket"
  config.aws_acl    = "public"

  config.aws_credentials = {
      access_key_id:     Rails.application.secrets.aws_access_id,
      secret_access_key: Rails.application.secrets.aws_access_secret,
      region:            "us-east-1",
      stub_responses:    Rails.env.test? # Optional, avoid hitting S3 actual during tests
  }

end

Here is my uploader

class VideoUploader < CarrierWave::Uploader::Base
  storage :aws

  def store_dir
    "uploads/video"
  end

  # You can find a full list of custom headers in AWS SDK documentation on
  # AWS::S3::S3Object
  def download_url(filename)
    url(response_content_disposition: %Q{attachment; filename="#{filename}"})
  end

  # Add a white list of extensions which are allowed to be uploaded.
  def extension_white_list
    %w[mov mp4 avi]
  end

end

Update: Here is what comes from the console, if it helps

F, [2018-07-12T13:45:26.804276 #9635] FATAL -- : NoMethodError (undefined method `match' for nil:NilClass
Did you mean?  catch):
F, [2018-07-12T13:45:26.804296 #9635] FATAL -- :   
F, [2018-07-12T13:45:26.804313 #9635] FATAL -- : [...]video_controller.rb:24:in `upload'

Any ideas?

mkeefe commented 6 years ago

Here is the video_controller.rb upload() method, if needed.

def upload
    video = params[:video]
    if video

      file_data = File.open(video.tempfile.path)

      logger.info file_data.path
      logger.info file_data

      # Send file to Amazon S3 bucket and grab URL
      uploader = VideoUploader.new
      uploader.store!(file_data) # <-- This line is where the app dies - NoMethodError

    end
end
mkeefe commented 6 years ago

Fixed! The problem was pretty stupid. The initializer file was in the environments directory, not the initializers, don't code on an empty stomach. Would be great if the code could detect that, but solved.