Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant AWS::S3::Base

I have this code which is in lib folder. This code works outside of rails, but when it's called from the rails controller I get the uninitialized constant AWS::S3::Base error

require 'rubygems'
require 'aws/s3'

module S3Util

  def self.upload_file(local_file)
    mime_type = "application/octet-stream"
    bucket = "test"

    AWS::S3::Base.establish_connection!(
      :access_key_id     => '*****',
      :secret_access_key => '****'
    )

    base_name = File.basename(local_file)

    puts "**** Uploading #{local_file} as '#{base_name}' to '#{bucket}'"

    AWS::S3::S3Object.store(
      base_name,
      File.open(local_file),
      bucket,
      :content_type => mime_type
    )

    puts "***** Uploaded!"

  end
end
like image 986
ed1t Avatar asked Feb 16 '26 08:02

ed1t


1 Answers

just do in your controller

require 'aws/s3'

and its work for me

like image 66
manish nautiyal Avatar answered Feb 18 '26 00:02

manish nautiyal