Class: IPASend::S3Uploader
- Inherits:
-
Object
- Object
- IPASend::S3Uploader
- Defined in:
- lib/ipasend/s3_uploader.rb
Constant Summary collapse
- DEFAULT_ENDPOINT =
's3-eu-west-1.amazonaws.com'
Instance Method Summary collapse
-
#initialize(options) ⇒ S3Uploader
constructor
A new instance of S3Uploader.
- #upload(key, data) ⇒ Object
Constructor Details
#initialize(options) ⇒ S3Uploader
Returns a new instance of S3Uploader.
7 8 9 10 11 12 13 14 |
# File 'lib/ipasend/s3_uploader.rb', line 7 def initialize() @s3 = AWS::S3.new( :s3_endpoint => .aws_endpoint || DEFAULT_ENDPOINT, :access_key_id => .aws_key, :secret_access_key => .aws_secret ) @s3_bucket = @s3.buckets[.aws_bucket] end |
Instance Method Details
#upload(key, data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ipasend/s3_uploader.rb', line 16 def upload(key, data) s3_object = @s3_bucket.objects[key] = ProgressBar.create(:title => "Uploading '#{key}'", :total => data.size, :format => '%e |%b>>%i| %p%% %t') s3_object.write(:content_length => data.size, :acl => :public_read) do |buffer, bytes| buffer.write(data.read(bytes)) .progress += bytes rescue nil end .finish s3_object end |