Class: S3Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/s3utils.rb

Overview

wrapper for S3 operations

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, bucket_name, server, region) ⇒ S3Utils

Returns a new instance of S3Utils.



7
8
9
10
11
12
# File 'lib/s3utils.rb', line 7

def initialize(access_key_id, secret_access_key, bucket_name, server,region)
  @bucket_name   = bucket_name
  @s3_connection = connect(access_key_id, secret_access_key,server, region)
  @s3_bucket     = get_or_create_bucket
  self
end

Instance Method Details

#delete(file_path) ⇒ Object



19
20
21
# File 'lib/s3utils.rb', line 19

def delete(file_path)
  @s3_bucket.objects[File.basename(file_path)].delete
end

#listObject



23
24
25
26
27
# File 'lib/s3utils.rb', line 23

def list
  @s3_bucket.objects.each do |obj|
    puts "#{obj.bucket.name}/#{obj.key}"
  end
end

#store(file_path, remote_path = nil) ⇒ Object



14
15
16
17
# File 'lib/s3utils.rb', line 14

def store(file_path, remote_path=nil)
  upload_location = (!remote_path.nil? && !remote_path.empty?) ? "#{remote_path}/#{File.basename(file_path)}" : File.basename(file_path)
  @s3_bucket.objects.create(upload_location, open(file_path))
end