Class: S3::Client
- Inherits:
-
Object
- Object
- S3::Client
- Defined in:
- lib/aws_docker_utils/s3/client.rb
Constant Summary collapse
- DEFAULT_REGION =
"us-east-1"
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #put(file_path) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/aws_docker_utils/s3/client.rb', line 9 def initialize(opts={}) @bucket_name = opts[:bucket_name] config = YAML.load(File.read(File.join(File.dirname(__FILE__), "credentials.yml"))) client = Aws::S3::Client.new( region: (config["region"] || DEFAULT_REGION), access_key_id: config["access_key"], secret_access_key: config["secret_key"] ) @s3 = Aws::S3::Resource.new(client: client) end |
Instance Method Details
#put(file_path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aws_docker_utils/s3/client.rb', line 21 def put(file_path) raise "Please set bucket name with constructor." if @bucket_name.nil? bucket = create_bucket(@bucket_name) obj = bucket.object(File.basename(file_path)) if obj.upload_file(file_path) return true else puts "could not upload file #{@file_path} to S3." end false end |