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
just do in your controller
require 'aws/s3'
and its work for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With