class Stratosphere::AWS::S3
Attributes
bucket_name[RW]
credentials[RW]
presigner[RW]
region[RW]
resource[RW]
Public Class Methods
new(config={})
click to toggle source
# File lib/stratosphere/aws.rb, line 6 def initialize(config={}) key = config.aws[:access_key] secret = config.aws[:secret] @region = config.aws[:region] @bucket_name = config.aws[:s3_bucket] @credentials = Aws::Credentials.new(key, secret) @resource = Aws::S3::Resource.new(credentials: @credentials, region: @region) @presigner = Aws::S3::Presigner.new(region: @region) Aws.config[:region] = @region Aws.config[:credentials] = @credentials end
Public Instance Methods
bucket()
click to toggle source
# File lib/stratosphere/aws.rb, line 18 def bucket resource.bucket bucket_name end
delete_objects(prefix)
click to toggle source
# File lib/stratosphere/aws.rb, line 22 def delete_objects(prefix) threads = [] bucket.objects(prefix: prefix).limit(50).each { |object| threads.push Thread.new { object.delete if object } } threads.each(&:join) end
presigned_upload(options={})
click to toggle source
# File lib/stratosphere/aws.rb, line 32 def presigned_upload(options={}) unless options.has_key?(:acl) options = options.merge({:acl => "public-read"}) end params = options.keep_if { |k,v| [:key, :content_type, :content_length, :acl, :cache_control].include? k }.merge!(bucket: bucket_name) presigner.presigned_url(:put_object, params) end
upload(options={})
click to toggle source
# File lib/stratosphere/aws.rb, line 28 def upload(options={}) bucket.put_object(options) end