Class: AionS3::Uploader
- Inherits:
-
Object
- Object
- AionS3::Uploader
- Defined in:
- lib/aion_s3/uploader.rb
Overview
An Uploader
is a utility for uploading data to s3. The Uploader supports compliance locking, where files are locked for update/deletion for a configured amount of time.
The utility is a wrapper around Aws::S3::Client
.
Instance Attribute Summary collapse
- #client ⇒ Aws::S3::Client readonly
Instance Method Summary collapse
-
#get(key, target = nil) ⇒ Aws::S3::Types::GetObjectOutput
Gets metadata from an object in s3.
-
#initialize(bucket, lock_days: 0, s3_options: {}) ⇒ Uploader
constructor
A new instance of Uploader.
-
#put(key, body) ⇒ Aws::S3::Types::PutObjectOutput
Puts an object to s3.
Constructor Details
#initialize(bucket, lock_days: 0, s3_options: {}) ⇒ Uploader
Returns a new instance of Uploader.
17 18 19 20 21 |
# File 'lib/aion_s3/uploader.rb', line 17 def initialize(bucket, lock_days: 0, s3_options: {}) @client = Aws::S3::Client.new() @bucket = bucket @lock_seconds = lock_days.to_i * 24 * 60 * 60 end |
Instance Attribute Details
#client ⇒ Aws::S3::Client (readonly)
12 13 14 |
# File 'lib/aion_s3/uploader.rb', line 12 def client @client end |
Instance Method Details
#get(key, target = nil) ⇒ Aws::S3::Types::GetObjectOutput
Gets metadata from an object in s3.
If a target is provided, the object data will be downloaded as well. target
must be a string with file path or an IO
object.
31 32 33 34 35 36 37 |
# File 'lib/aion_s3/uploader.rb', line 31 def get(key, target = nil) @client.get_object( bucket: @bucket, key: key, response_target: target ) end |
#put(key, body) ⇒ Aws::S3::Types::PutObjectOutput
Puts an object to s3.
If Uploader
was configured with lock_days > 0 a compliance lock will be put on the object.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aion_s3/uploader.rb', line 46 def put(key, body) = { bucket: @bucket, key: key, body: body, } if @lock_seconds > 0 .reverse_merge!( object_lock_mode: 'COMPLIANCE', object_lock_retain_until_date: Time.now + @lock_seconds ) end @client.put_object() end |